I am attempting to create a provisioning form wherein the user selects a value from one dropdown, and the subsequent dropdown’s allowed values are set based on that value.
For example, if a user selects the state “Texas” from the “state” field, then the following “city” field should be a dropdown of “Austin, Dallas, Houston”, but if they change their selection to “California” the city dropdown should now only allow “LA, San Diego, Pasadena”
I have tried the following flags on the form fields:
As well as the following test code on the AllowedValuesDefinition of the City field
import sailpoint.object.field;
Field stateField = form.getField("state");
if (stateField != null) {
// code to set allowed values based on stateField value
}
However, stateField is seemingly always null, no matter what I have selected in it on the provisioning form. Does allowedValuesDefinition not run on postback refresh or am I referencing the field wrong?
The only remaining issue I have is that a user can select “Texas”, then choose a Texas city, but then switch their state to “California” and submit the form without changing city. Now they have an invalid State/City combination.
You can use a rule to dynamically populate ‘DynamicValue’ object to populate the form field values dynamically (AllowedValuesDefinition population using rule, clear the value/set field value null in case the rule gets executed when the value is changed for the dropdown 1.
Add a DefaultValue script on the City field that returns null` when the state changes, below is the example:
Since the City field has dynamic=“true”, every time the State field posts back, the City field is re-rendered and When it re-renders, the DefaultValueDefinition fires and sets the value back to null.
"NOTE: Field value recalculations for fields marked as dynamic are not processed on postBack if a value has been entered manually in the field, based on the assumption that if a user manually enters a value, they generally do not want that overridden by an automatic process. To override this behavior, manually clear the fields using a hidden script elsewhere in the form..."
Have a workaround I’ve used myself a few times when running into this issue. You can use a hidden script to clear the value from the field when the new value would not be allowed based on the dependent field value updating.
This post does a good job walking through this use case. Hope this helps!
This post was answered by a Palyrian Solutions Architect. Feel free to message me directly if your problem requires a deeper dive. palyrian.com | (301) 284-8124
Hi @chris-hogan Yep, this code looks good, but the business case needs a small correction. It will work, I think, if we add clear the value from the field object if they change the state. field.setValue(““);