Dropdown marco expression

Suneel Jhangiani asked on August 2, 2018 18:38

I've created a custom field that I'd like the user to select a year from a drop down list. I have used the following macro expression to populate the dropdown:

y = DateTime.now.year-50; x=DateTime.now.year; while (y<x) {++y}

This results in a dropdown holding the last 50 years. What I'm struggling with is adding a 'Please select' entry (ideally with a value of 0).

Correct Answer

Dragoljub Ilic answered on August 2, 2018 21:52

Hi Suneel,

Like Peter suggested you, you should go with that approach, but you must return array at the end. I tweaked a little bit Peter's solution with simple splitting at the end by ';' char and it worked well. Check code snippet bellow: {%y = DateTime.now.year-50; x=DateTime.now.year; result ="Please Select;"; while (y<x) { year=++y; result+=year+";"; } return result.split(";");#%}

Best regards, Dragoljub

0 votesVote for this answer Unmark Correct answer

Recent Answers


Peter Mogilnitski answered on August 2, 2018 19:08

{%y = DateTime.now.year-50; x=DateTime.now.year; result ="Please Select"; while (y<x) { year=++y; result+=year; } return result;#%}

1 votesVote for this answer Mark as a Correct answer

Suneel Jhangiani answered on August 2, 2018 20:02

Peter, using that as a macro expression for the dropdown-list form control results in a single item with "Please select196919701971...."

0 votesVote for this answer Mark as a Correct answer

Suneel Jhangiani answered on August 2, 2018 22:55

Thanks to both of you. It was actually the Split at the end that I needed.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.