How to Set a Field Value Based on Another Field in a Form?

Hey everyone,

I created a quick link that includes a workflow. In one of the workflow steps, there’s a form with multiple fields. I need to set the value of a specific field based on the value of another field within the same form.

Is there a way to write a rule for this field to dynamically assign its value depending on the other field? If so, how can I do it?

Any guidance would be greatly appreciated!

Thanks in advance. :blush:

Hi @lojainahmed,

if I understand your requirement correctly then you have to configure the first field to contain “postback=true” and add a value script to the second field (which is dependent) like in the following example:

<Field displayName="Company Id" dynamic="true" hidden="true" name="companyId" type="string">
      <Attributes>
        <Map>
          <entry key="hidden" value="true"/>
        </Map>
      </Attributes>
      <Script>
        <Source><![CDATA[
					
			String _company = null;
			_company = form.getField("company").getValue();
		        <!-- Do some logic here -->
                        return "xyz";
			]]></Source>
      </Script>
    </Field>

Best regards,
Daniel

2 Likes

You need to make sure your first field on which the value of second field is depended is set postBack=“true” and the second field is set with dynamic=“true”. Here is a sample

          <Field  name="userType" postBack="true" required="true" type="string">
            <AllowedValues>
              <String>User Type A</String>
              <String>User Type B</String>
              <String>User Type C</String>
              <String>User Type D</String>
            </AllowedValues>
          </Field>
		  <Field dynamic="true" name="secondField" readOnly="true" type="string">
            <Script>
              <Source>
								if(userType != null){
									if(userType.equalsIgnoreCase("User Type A")){
										return "A";
									}
									if(userType.equalsIgnoreCase("User Type B")){
										return "B";
									}
									if(userType.equalsIgnoreCase("User Type C")){
										return "C";
									}
									if(userType.equalsIgnoreCase("User Type D")){
										return "D";
									}
								}
			 </Source>
            </Script>
          </Field>
2 Likes

Hello Sanjeev, Thank you so much for your answer

i tried your code but i have a problem: the fied: managerForm is of type sailpoint.object.Identity, but when i try to cast it to identity in the script of the other field like this picture, it gives me an exception: “Cannot cast java.lang.String to sailpoint.object.Identity BSF info: script at line: 0 column: columnNo”, although the field “managerForm” is of type identity not string.

please note that the field “managerForm” is a drop down field, where the user chooses his manager.

Thank you, Daniel! Your solution worked perfectly for me. I really appreciate your help and the time you took to assist :heart:

Hi Lojain,
The Identity type field returns Identity id and not Identity object. You can use something like the following to get the actual identity object using the id value

if(managerForm != null){
Identity managerIdentity = context.getObjectById(Identity.class, managerForm);
return managerIdentity.getDisplayName();
}
1 Like

Thank you, Sanjeev! Your solution worked perfectly. I really appreciate your help and the time you took to guide me :heart: