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!

1 Answer 1

4

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>
1
  • Thanks, @Adam Spriggs! It works like a charm! Appreciate your help! :D Oct 24, 2017 at 3:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .