I have a data driven dropdown in my form and I want to prefill data into it on form load.
How do I do this?
To Prefill data from a prefill service. Follow the example below.
In this case we want a list of the US State names in the dropdown. So we will use a pipe delimited string to prefill into a StatesList key in the form data object.
To access this string in the Maestro form use the following code:
The Form.prefill object contains all the prefilled data, and StatesList is the key used to prefill in this case.
Add a Form Load Rule to store this data in the Form.data object so we can use it in our data driven dropdown:
Open Form Options:
Select Form Rules:
Create a Form Load rule with the following code:
data.$statesList = Calc.pipedSelection(Form.prefill.StatesList);
There are a couple of things happening here:
The Calc.pipedSelection method will take in the pipe delimited string and convert it into an array of objects. This is the format supported by the data driven dropdown.
We will store this array in a special dollar sign key called data.$statesList, this is because we do not want this data in the XML and won't be changing it dynamically during the form run time. (If we want to add more in the form we can do this by pushing more objects into this array. Or use a data field to hold the data).
Save the rule.
Drop a data driven dropdown into the form
Set the Data Source to be data.$statesList
And you are ready to go.
Some related information here:
This approach doesn't seem to work when the dropdown is in a repeating element. Is there a workaround?