0

I have a numeric field (max_count__c) which is retrieved from sales cloud. This field can range from value 1 to 5.

In cloudpage, my landing page is supposed to display a dynamic dropdown list based on the value entered in max_count__c in Sales cloud.

E.g. If max_count__c is 3 in sales cloud, my dropdown list in my html form should be showing a dropdown list of 3 values (1, 2 and 3). A sample of my code is as follows:

<html lang="en">
  <head>
  </head>
  <body>

%%[ 
var @scintfields, @maxcount  

set @scintfields= RetrieveSalesforceObjects('Campaign', 'max_count__c', 'Id', '=', @campaignid)

Set @maxcount = FormatNumber(FIELD(ROW(@scintfields,1), 'max_count__c'),"F0")

]%%
<form action="%%=v(@deflandingpage)=%%" method="post">
<!--note this dropdown section should be dynamic instead of being hard-coded to have 3 options -->
<select name="maxcount">
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
</select>
<br> 
<input id="submitted" type="hidden" name="submitted" value="submitted" />
<input type="hidden" name="submit" value="1" />
<input type ="submit" value="Submit">
</form>
<body>
</html>

I understand that a FOR loop should be applied in order for the dropdown list to be dynamic. However I am quite new to html / javascript. Can someone assist me in this issue and guide me on how to include a FOR loop in my current codes if a FOR loop is required?

Thanks!

3

For reference, AMPScript for-loops are documented here on the developer site.

I'd code it like this:

<html lang="en">
  <head>
  </head>
  <body>

%%[ 

var @scintfields, @maxcount  

set @scintfields = RetrieveSalesforceObjects('Campaign', 'max_count__c', 'Id', '=', @campaignid)

]%%

<form action="%%=v(@deflandingpage)=%%" method="post">

%%[ 

if rowcount(@scintfields) > 0 then 

    Set @maxcount = FormatNumber(field(row(@scintfields,1), 'max_count__c'),"F0") 

]%%

    %%[ if @maxCount > 0 then ]%%


    <select name="maxcount">
      <option value="">Select</option>

      %%[ for @i = 1 to @maxcount do ]%%

        <option value="%%=v(@i)=%%">%%=v(@i)=%%</option>

      %%[ next @i ]%%  

    </select>

    %%[ else ]%%

        <br>Options not found 

    %%[ endif ]%%

%%[ else ]%%

    <br>Campaign object not found

%%[ endif ]%%
<br> 
<input id="submitted" type="hidden" name="submitted" value="submitted" />
<input type="hidden" name="submit" value="1" />
<input type ="submit" value="Submit">
</form>
<body>
</html>
| improve this answer | |
  • Thanks, @Adam Spriggs! It works like a charm! Appreciate your help! :D – Valarie Simmons Oct 24 '17 at 3:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.