How to get application object in a form with displayType as listbox and which uses AllowedValuesDefinition with a script

Version 8.4 p4

Hi

I am trying to build a provisioning form which has a listbox as field in it

This is using AllowedValuesDefinition and I am adding a script in it

I am trying to access application object inside the script

What is the best way to get this object in the provisioning form ?

Can I use form.getField(“application”).getValue() ?

Thanks

Hi @guptaMani - can you elaborate more on your use case?

Is this an application provisioning form like a create policy?

What value are you wanting to return, application name?

Since it is a list, what else are you needing in it?

Hi @guptaMani ,
You can add an applicationName field, and using value setting, you can set the application name and get that field form.getFiled(“applicationName”); or try direct field variable applicationName might work.

or

you can create a custom object and add list of appllication and using a rule, you can return those applications for allowedvaluesDefination.

@guptaMani

Using form.getField(“application”).getValue() will only work if you explicitly have a field named “application” in your form that holds the application’s name as its value.

@guptaMani Do you want to show all the application names available in your environment in the dropdown of your listbox field? If so, set the type to Application and it’ll show all the apps name in the dropdown. You can access field using the field name directly in your allowed rule.

@ryan_toornburg, Its a create provisioning form

I am pulling the values from a custom object which has a key as app name and value as a list of strings in a map

I will be matching the appname with key and return the values in that map

@sukarande, Can you please elaborate on that or give me an example.

Its a create provisioning form

I am pulling the values from a custom object which has a key as app name and value as a list of strings in a map

I will be matching the appname with key and return the values in that map

@neel193 Its a create provisioning form

I am pulling the values from a custom object which has a key as app name and value as a list of strings in a map

I will be matching the appname with key and return the values in that map

@Vinodcsod, Its a create provisioning form

I am pulling the values from a custom object which has a key as app name and value as a list of strings in a map

I will be matching the appname with key and return the values in that map

Please share your custom object, form and rule that you currently have. Will review and let you know how to get this.

Custom object


<?xml version='1.0' encoding='UTF-8'?> sample file Unused sample2 file2 Unused2


Form

        import java.util.ArrayList;
        import java.util.List;
        import sailpoint.object.Custom;
        import sailpoint.object.Application;

		String appName = "";
        
        if(form !=null @and null != form.getField("application")){
			String appName = (String) form.getField("application").getValue();
        }
        
        Custom customObject = context.getObjectByName(Custom.class, "Custom ABC");
    
        if (customObject != null @and form!= null) {
        	Map map = customObject.getAttributes();
        	
          List list = (List) map.get(appName);
        	return list;
        }
        return new ArrayList();

      </Source>
    </Script>
  </AllowedValuesDefinition>
</Field>


<Custom name="Custom ABC">
  <Attributes>
    <Map>
      <entry key="App 1">
        <value>
          <List>
            <String>sample</String>
            <String>file</String>
            <String>Unused</String>
          </List>
        </value>
      </entry>
      <entry key="App 2">
        <value>
          <List>
            <String>sample2</String>
            <String>file2</String>
            <String>Unused2</String>
          </List>
        </value>
      </entry>
	 </Map>
  </Attributes>
</Custom>
```
There is no rule

Thanks. Let me add to my sandbox and get back.

Hi @guptaMani ,

Can you try adding the following code to your form to get the values from Custom object based on the selected application.

<Field displayName="Application" name="appId" postBack="true" required="true" type="Application"/>
          <Field displayName="Custom Field" name="customField" postBack="true" type="string">
            <AllowedValuesDefinition>
              <Script>
                <Source>
                  import sailpoint.object.Custom;
                  import sailpoint.tools.Util;
                  import sailpoint.object.Application;

                  import org.apache.log4j.Logger;

                  Logger mylog = Logger.getLogger("com.example.customLogs");

                  String appName = null;

                  mylog.error("Application ID : " + appId);

                  if(appId!=void &amp;&amp; Util.isNotNullOrEmpty(appId)){

                  Application application = context.getObjectById(Application.class,appId);

                  if(application!=null &amp;&amp; Util.isNotNullOrEmpty(application.getName())){

                  appName = application.getName();

                  mylog.error("App Name : " + appName);

                  }

                  }

                  mylog.error("Application Name : " + appName);

                  if(appName!=null){

                  Custom custom = context.getObjectByName(Custom.class,"Custom ABC");

                  if(custom!=null){

                  List list = custom.getList(appName);

                  if(list!=null &amp;&amp; !list.isEmpty()){

                  return list;

                  }
                  }
                  }

                </Source>
              </Script>
            </AllowedValuesDefinition>
          </Field>

Let me know if you are facing any issues.

The code works but its prompting the user to enter the application name

What if I don’t want the user to enter the application but the form should read it from the application its currently attached to. (Since its application provisioning form)

If I remove required=“true”, will it still show the field and need input from user ?

Thanks

@guptaMani So, IIQ is presenting the provisioning policies as Identity Update workitem form, not as provisioning policy and there is object available which can directly reference to the application.
One thing you can try is you can have separate allowed value rule for each app+provisioning policy combo. in the rule you can hard code the application name and show the value in the dropdown after reading from custom object:

String appName = "TRAKK";
Custom customObj = context.getObjectByName(Custom.class,"Custom ABC");
if(customObj!=null){
List entryList = customObj.getList(appName);
if(entryList!=null &amp;&amp; !entryList.isEmpty()){
return entryList;
}
return new ArrayList();

And if you remove required=true, then if field doesn’t have any value set then only it’ll prompt user to enter the value.

I wanted to make the form more generic to be used for multiple applications

Also, for comments, when I remove the required=“true” in the field, it doesn’t show the field itself. Is this expected ?

This is how the field looks like. I wanted to make comments optional

<Field displayName="Add comments" name="Comment" required="true" type="string"/>

Hi @guptaMani ,

Can you try adding the following code to your Provisioning Form instead of the above code to get dynamic allowed values based on the application.

 <Field displayName="Custom Field"  dynamic="true" name="customField" postBack="true" reviewRequired="true" type="string">
          <AllowedValuesDefinition>
            <Script>
              <Source>
                import org.apache.log4j.Logger;

                import java.util.List;
                import java.util.ArrayList;
                
                import sailpoint.object.Custom;

                String appName=null;

                if(field!=null){

                appName = field.getApplication();

                if(appName!=null){

                Custom custom = context.getObjectByName(Custom.class,"Custom ABC");

                if(custom!=null){

                List list = custom.getList(appName);

                if(list!=null &amp;&amp; !list.isEmpty()){

                return list;

                }
                }
                }
                }                

              </Source>
            </Script>
          </AllowedValuesDefinition>
        </Field>



And if you want to display ‘Add Comments’ to user, then you need to set reviewRequired=“true” and to make comments optional set required=“false”

Thanks for sharing @Chathuryas

@guptaMani field.getApplication returns the app name, form is associated with. @Chathuryas thanks for sharing.