How to fetch other field value from the same form.(Provisioning Form)

In Provisioning Form How to fetch other field value from the same form.For eg: I want Employee ID to be depend on the type of Department. So how can i fetch the Department value .

I m using : Field identityNameSelectedField = form.getField(“identityNameSelected”); but i getting error . and i am putting it in value–> rule

can you add your Form xml?

Hi @Shubhangani_Kharayat,

Hope you’re doing well!

To fetch another field’s value from the same provisioning form, you can use the getValue():

String identityNameSelectedValue = (String) form.getField("identityNameSelected").getValue();

A couple of important points to keep in mind:

  1. Ensure the field you want to reference is correctly defined in the form XML with the exact name attribute.

  2. Mark the dependent field as dynamic=“true”, so its value can be recalculated whenever the source field changes.

  3. If you want the form to refresh when the source field changes (e.g., Department → Employee ID), set postback=“true” on the source field.

  4. Always handle possible null values to avoid runtime errors, especially when the form is first opened, when no values ​​have yet been set.

Hope it helps.

I m getting error when i m using : String identityNameSelectedValue = (String) form.getField(“identityNameSelected”).getValue();

An unexpected error occurred: Exception evaluating rule: Test Typed variable declaration : Attempt to resolve method: getField() on undefined variable or class name: form : at Line: 1

Hi, @Shubhangani_Kharayat.

Looks like you’re working on a different context than the provisioning form.

Please try to use the imbedded form script instead of a rule. Make sure that the field for Employee ID (or whichever dependent field you’re building) is defined after the identityNameSelected field, or set the identityNameSelected field as a dependency for the Employee ID field.

You have to should be able to reference the other field directly by name without needing to call form.getField(…). Like the below example:

<Form name="myform">

<Section>

<Field displayName="First Name" name="firstname" type="string"/>

<Field displayName="Last Name" name="lastname" postBack="true" type="string"/>

<Field displayName="Username" dynamic="true" name="name" type="string">

<Script>

<Source>

if ((null != firstname) &amp;&amp; (null != lastname)) {

return (firstname + "." + lastname);

}

return null;

</Source>

</Script>

</Field>

</Section>

</Form>

If possible, attach your form xml, so we can take a better look into it.

Hope it helps.

Thanks it’s working..