Creating a Drop-Down from the results chosen from another drop-down in a form

I have created the following drop-down in my create identity form:

  <Field displayName="Type of Account" helpKey="Choose from the following in the dropdown: AA, ZZ or Regular Account" name="adminacct" postBack="true" required="true" type="string">
      <AllowedValuesDefinition>
        <Value>
          <List>
            <String>AA</String>
            <String>ZZ</String>
            <String>Regular Account</String>
          </List>
        </Value>
      </AllowedValuesDefinition>
    </Field>

What I would like to see performed is when one of the 3 above is chosen, then another drop-down automatically comes up right after the selection with whatever choices are the result of the above choice. Could you please assist on how this would be written?

I have already made a custom object as shown below if “AA” is the chosen one.

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Custom PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<Custom name="AA Admin Titles">
  <Attributes>
    <Map>
      <entry key="1" value="This Guy"/>
      <entry key="2" value="That Guy"/>
      <entry key="3" value="Some Guy"/>
	  <entry key="4" value="The Other Guy"/>
    </Map>
  </Attributes>
</Custom>

You would need to set the needed fields to be dynamic and use dependencies. You can also set a field to hidden and un-hide it via a filed script that’s updated when a different field is set. It’s not noted in the documentation here I don’t think, but the hidden attribute exists and works for individual fields the same way it does for form sections.

https://community.sailpoint.com/t5/Technical-White-Papers/Forms-7-0-and-later/ta-p/79191#toc-hId-677057407

Implement your second field in this way, it will help you achieve what you needed, I assume you wanted to show only the keys in custom object based on the First field selection 


<Field displayName="Account Name" dependancies="adminacct" helpKey="Choose from the following in the dropdown" name="acctName" postBack="true" dynamic="true" required="true" type="string">
  <AllowedValuesDefinition>
    <Script>
      <Source>
        import sailpoint.object.Form;
        import sailpoint.object.Field;
        import java.util.List;
        import java.util.ArrayList;
        import java.util.Map;
        import sailpoint.object.Custom;
        import sailpoint.object.Attributes;


        String selectedValue = form.getFieldValue("adminacct");

        List&tl;String> options = new ArrayList&lt;String>();

        if (selectedValue != null) {



        if (selectedValue.equals("AA")) {
        Custom customObject = context.getObjectByName(Custom.class, "AA Admin Titles");
        if (customObject != null) {
        Map mapAttribute = customObject.getAttributes();
        options = new ArrayList&lt;String>(mapAttribute.keySet());

        }
        }
        else if (selectedValue.equals("ZZ")) {
        Custom customObject = context.getObjectByName(Custom.class, "ZZ Admin Titles");
        if (customObject != null) {
        Map mapAttribute = customObject.getAttributes();
        options = new ArrayList&lt;String>(mapAttribute.keySet())
        }
        }


        }
        return options;


      </Source>
    </Script>
  </AllowedValuesDefinition>
</Field>
type or paste code here
2 Likes

Hi Satish,

I am getting the following error in the screenshot below:

I see there is something also wrong with the displayname line as well. Could you please help?

You can change the script slightly to fix the error as below.

    <Field dependencies="adminacct" displayName="Account Name" dynamic="true" helpKey="Choose from the following in the dropdown" name="acctName" postBack="true" required="true" type="string">
      <AllowedValuesDefinition>
        <Script>
          <Source>
            import sailpoint.object.Form;
            import sailpoint.object.Field;
            import java.util.List;
            import java.util.ArrayList;
            import java.util.Map;
            import sailpoint.object.Custom;
            import sailpoint.object.Attributes;
            
            String selectedValue = form.getField("adminacct").getValue();
            
            List options = new ArrayList();
            
            if (selectedValue != null) {
              if (selectedValue.equals("AA")) {
                Custom customObject = context.getObjectByName(Custom.class, "AA Admin Titles");
                if (customObject != null) {
                  Map mapAttribute = customObject.getAttributes();
                  options = new ArrayList(mapAttribute.keySet());
                }
              } else if (selectedValue.equals("ZZ")) {
                Custom customObject = context.getObjectByName(Custom.class, "ZZ Admin Titles");
                if (customObject != null) {
                  Map mapAttribute = customObject.getAttributes();
                  options = new ArrayList(mapAttribute.keySet());
                }
              }
            }
            return options;
          </Source>
        </Script>
      </AllowedValuesDefinition>
    </Field>

The script saved correctly but when I go back to form, it does not list the names from my AA Admin Titles custom objects. it only list the numbers as shown below:

Could there be something wrong with my custom object?

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Custom PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<Custom name="AA Admin Titles">
  <Attributes>
    <Map>
      <entry key="1" value="This Guy"/>
      <entry key="2" value="That Guy"/>
      <entry key="3" value="Some Guy"/>
	  <entry key="4" value="The Other Guy"/>
    </Map>
  </Attributes>
</Custom>

You can change mapAttribute.keySet() to mapAttribute.values().

    <Field dependencies="adminacct" displayName="Account Name" dynamic="true" helpKey="Choose from the following in the dropdown" name="acctName" postBack="true" required="true" type="string">
      <AllowedValuesDefinition>
        <Script>
          <Source>
            import sailpoint.object.Form;
            import sailpoint.object.Field;
            import java.util.List;
            import java.util.ArrayList;
            import java.util.Map;
            import sailpoint.object.Custom;
            import sailpoint.object.Attributes;
            
            String selectedValue = form.getField("adminacct").getValue();
            
            List options = new ArrayList();
            
            if (selectedValue != null) {
              if (selectedValue.equals("AA")) {
                Custom customObject = context.getObjectByName(Custom.class, "AA Admin Titles");
                if (customObject != null) {
                  Map mapAttribute = customObject.getAttributes();
                  options = new ArrayList(mapAttribute.values());
                }
              } else if (selectedValue.equals("ZZ")) {
                Custom customObject = context.getObjectByName(Custom.class, "ZZ Admin Titles");
                if (customObject != null) {
                  Map mapAttribute = customObject.getAttributes();
                  options = new ArrayList(mapAttribute.keySet());
                }
              }
            }
            return options;
          </Source>
        </Script>
      </AllowedValuesDefinition>
    </Field>

If you are only using value from the custom object, you can have the custom object in this format.

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Custom PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<Custom name="AA Admin Titles">
  <Attributes>
    <Map>
      <entry key="Attributes">
        <value>
          <List>
            <String>That Guy</String>
            <String>Some Guy</String>
            <String>The Other Guy</String>
            <String>This Guy</String>
          </List>
        </value>
      </entry>
    </Map>
  </Attributes>
</Custom>

And if you are using Custom object in this format , you might have to change the script slightly.
mapAttribute.keySet() to mapAttribute.get("Attributes")

    <Field dependencies="adminacct" displayName="Account Name" dynamic="true" helpKey="Choose from the following in the dropdown" name="acctName" postBack="true" required="true" type="string">
      <AllowedValuesDefinition>
        <Script>
          <Source>
            import sailpoint.object.Form;
            import sailpoint.object.Field;
            import java.util.List;
            import java.util.ArrayList;
            import java.util.Map;
            import sailpoint.object.Custom;
            import sailpoint.object.Attributes;
            
            String selectedValue = form.getField("adminacct").getValue();
            
            List options = new ArrayList();
            
            if (selectedValue != null) {
              if (selectedValue.equals("AA")) {
                Custom customObject = context.getObjectByName(Custom.class, "AA Admin Titles");
                if (customObject != null) {
                  Map mapAttribute = customObject.getAttributes();
                  options = new ArrayList(mapAttribute.get("Attributes"));
                }
              } else if (selectedValue.equals("ZZ")) {
                Custom customObject = context.getObjectByName(Custom.class, "ZZ Admin Titles");
                if (customObject != null) {
                  Map mapAttribute = customObject.getAttributes();
                  options = new ArrayList(mapAttribute.keySet());
                }
              }
            }
            return options;
          </Source>
        </Script>
      </AllowedValuesDefinition>
    </Field>

I have already mentioned, assuming you need keys you can use this code, if you want to display Values you can follow what suggested by @Jarin_James

Also I have given spaces earlier as the response is not getting saved, now corrected it.
you can refer it now

It is giving me error “Attempt to invoke method getValue on null value”
Please reply and help.

Hi @Jawadkalburgi

Are trying to implement the exact same thing, or it is something siilar. I would suggest you start a new post mentioning your issue, provide more information about your issue like what were you doing that led to this, where did you see it, what version of IIQ are you on, logs etc

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.