Hide Fields based on list's index

Hi,
I am using a Script to hide and unhide field where I am using the exact data the list have but instead I want to use list’s index to hide or unhide the field.

My code:

<Section label="Requesting For" name="Section 1">
	<Field displayName="Select" name="Field_1" postBack="true" required="true" type="string">
		<AllowedValuesDefinition>
			<Value>
				<List>
					<String>Option 1</String>
					<String>Option 2</String>
				</List>
			</Value>
		</AllowedValuesDefinition>
	</Field>
	<Field displayName="Enter Data" dynamic="true" name="Field_2" postBack="true" required="true" type="sailpoint.object.Identity">
		<Attributes>
			<Map>
				<entry key="hidden">
					<value>
						<Script>
							<Source>
import sailpoint.object.Field;

              Field f1 = form.getField("Field_1");
              String f1value = f1.getValue();
              boolean hideField = false;

              if(!("Option 1".equalsIgnoreCase (f1value))) {

              hideField= true; 
              field.setRequired(false);
              }
              else {

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

              Field f1 = form.getField("Field_1");
              String f1value = f1.getValue();
              boolean hideField = false;
              if(!("Option 2".equalsIgnoreCase (f1value))) {
              hideField= true; 
              field.setRequired(false);
              }
              else {
              field.setRequired(true);
              }
              return hideField;</Source>
						</Script>
					</value>
				</entry>
			</Map>
		</Attributes>
	</Field>
</Section>

Instead of using “Option 1” directly i.e. the 0th data in the list of options I want to use the 0 to the field which I want to show when 0th index data is selected from the list.
I tried using Index != 0, but its not working.

Hi @Krishna1,

you can use a rule(or a script) instead of fixed value where you return a List of couple of value(or a List of Array), where the first element will be value and the second will be the description, something like this:

ArrayList jobList = new ArrayList();
for(int i = 0; i < 2; i++){
     ArrayList arrayJobtitle = new ArrayList();
     arrayJobtitle.add(i);
     arrayJobtitle.add("Option " + i);
     jobList.add(arrayJobtitle);
}

return jobList;

so, when you read the value of selected element, it return 0 or 1