Hidden Field Alternate Approach

I have created Three fields.
1st field = Options to be selected
2nd and 3rd Field will be visible based on the options selected above.

<Section name="Section 1">
    <Field displayName="Requesting For" displayType="radio" name="Selection" postBack="true" required="true" type="string">
      <AllowedValuesDefinition>
        <Value>
          <List>
            <String>Option One</String>
            <String>Option Two</String>
          </List>
        </Value>
      </AllowedValuesDefinition>
    </Field>
    <Field displayName="Select ID" dynamic="true" name="First" postBack="true" type="sailpoint.object.Identity">
      <Attributes>
        <Map>
          <entry key="hidden">
            <value>
              <Script>
                <Source>
                  import sailpoint.object.Field;

                  boolean hideField = !"Option One".equalsIgnoreCase(form.getField("Selection").getValue());

                  field.setRequired(!hideField);
                  return hideField;
                </Source>
              </Script>
            </value>
          </entry>
        </Map>
      </Attributes>
    </Field>
    <Field displayName="Enter ID" dynamic="true" name="Second" postBack="true" type="string">
      
      <Attributes>
        <Map>
          <entry key="hidden">
            <value>
              <Script>
                <Source>
                  import sailpoint.object.Field;

                  boolean hideField = !"Option Two".equalsIgnoreCase(form.getField("Selection").getValue());

                  field.setRequired(!hideField);
                  return hideField;
                </Source>
              </Script>
            </value>
          </entry>
        </Map>
      </Attributes>
    </Field>
  </Section>

In case the option is long or there are alot of options, adding options in everyfield is a bit lengthy.
So I descided to use index. Here I will define all the options in a list and the fields will contain 0,1,2 … to hide or unhide them but did not work.

Also I tried giving value to every option like 0 or 1 and tried, it also seems not supported or something.
Any different approach I can try?

@pctripathi Can you explain the issue? I just tried importing this form section into my local and it is working fine.

@Arpitha1
Like in this code below

boolean hideField = !"Option One".equalsIgnoreCase(form.getField("Selection").getValue());

I am defining “Option One” so this field will be visbible if “Option One” is selected.

I want to use different scenario here, insted of defining the option in the script I want to use something more like a global variable, in case the option and number of options are too long to mention everytime in every field.

You can use below one. First you try with the script, if it works then keep it in a rule and can refer it in other fields too.

  boolean hideField = !field.getName().equalsIgnoreCase(form.getField("Selection").getValue());

Can you add your piece of code in mine which I have sent above so its clear how to get it working?

Attaching the code here

 <Section name="Section 1">
    <Field displayName="Requesting For" displayType="radio" name="Selection" postBack="true" required="true" type="string">
      <AllowedValuesDefinition>
        <Value>
          <List>
            <String>Option One</String>
            <String>Option Two</String>
          </List>
        </Value>
      </AllowedValuesDefinition>
      <OwnerDefinition value="IIQRequester"/>
    </Field>
    <Field displayName="Option One" dynamic="true" name="Option One" postBack="true" type="sailpoint.object.Identity">
      <Attributes>
        <Map>
          <entry key="hidden">
            <value>
              <Script>
                <Source>
                  import sailpoint.object.Field;

                  boolean hideField = !field.getName().equalsIgnoreCase(form.getField("Selection").getValue());

                  field.setRequired(!hideField);
                  return hideField;
                </Source>
              </Script>
            </value>
          </entry>
        </Map>
      </Attributes>
    </Field>
    <Field displayName="Enter ID" dynamic="true" name="Option Two" postBack="true" type="string">
      <AllowedValuesDefinition>
        <Script>
          <Source>
                  import sailpoint.object.Field;

                  boolean hideField = !field.getName().equalsIgnoreCase(form.getField("Selection").getValue());

                  field.setRequired(!hideField);
                  return hideField;
                </Source>
        </Script>
      </AllowedValuesDefinition>
    </Field>
  </Section>

Did not work after using this approach.

Are you getting any error? It worked fine to me