How to get list of accounts from Application

Hi all
I have a field which is getting all the applications Name in a dropdown field.

 <Field displayName="Select" dynamic="true" name="Field_6" postBack="true" required="true" type="Application"/>

I am also creating a field below to get the list of accounts in dropdown as multi in associated with the application selected.

  <Field displayName="Accounts" multi="true" name="Field_7" postBack="true" required="true" type="string"/>

What script should I use in order to get accounts associated with the application?

@pctripathi

Use AllowedValuesDefintion Script and write a code within that to get the application name and get all the accounts under the app

You can use below sample code, please add relevant field names of app name and import statements.

 QueryOptions linkQO = new QueryOptions();
  
  
 linkQO.addFilter(Filter.eq("application.id",applicationName));
  
Iterator iter=context.search(Link.class, linkQO);
List accountNames=new ArrayList();

while(iter.hasNext()){
accountNames.add(iter.next().getNativeIdentity());

}
return accountNames;
1 Like

Hi @iamksatish
modified the script template you shared.
It’s not showing accounts in field. Its coming as no result found. No matter what application I select.

Below is the code I changed

<Field displayName="Accounts" dynamic="true" multi="true" name="Field_7" postBack="true" required="true" type="string">
      <AllowedValuesDefinition>
        <Script>
          <Source>
import sailpoint.object.QueryOptions;
import sailpoint.object.Filter;
import sailpoint.object.Link;

    String applicationName = form.getField("Field_6").getValue();

    QueryOptions linkQO = new QueryOptions();
    linkQO.addFilter(Filter.eq("application.name", applicationName));

    Iterator iter = context.search(Link.class, linkQO);
    List accountNames = new ArrayList();

    while (iter.hasNext()) {
      Link link = (Link) iter.next();
      accountNames.add(link.getNativeIdentity());
    }

    return accountNames;
  </Source>
        </Script>
      </AllowedValuesDefinition>
    </Field>

Hi @pctripathi ,

Code will return the accounts associated with the application. Check and let me know.

 <Field displayName="Accounts" dynamic="true" multi="true" name="Field_7" postBack="true" required="true" type="string">
            <AllowedValuesDefinition>
              <Script>
                <Source>
import java.util.List;
import java.util.ArrayList;
import sailpoint.object.Application;
import sailpoint.object.Identity;
import sailpoint.object.Link;
import sailpoint.object.QueryOptions;
import sailpoint.object.Filter;
import java.util.Iterator;
import java.util.Collections;


String applicationName = form.getField("Field_6").getValue();
Application App = context.getObjectById(Application.class, applicationName);

List accountNames = new ArrayList();
Link link;
if(null!=App){
	QueryOptions qo=new QueryOptions();
  qo.addFilter(Filter.eq("application", App));

	List lstLinks = context.getObjects(Link.class,qo);
	if(lstLinks!=null){
		Iterator it=lstLinks.iterator();
		while(it.hasNext()){
			link = (Link) it.next();
			if(null != link &amp;&amp; !link.isDisabled()){
				 
                    accountNames.add(link.getNativeIdentity());
                   }              
				}
			}									
		}
	

               


Collections.sort(accountNames);
return accountNames;

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

Regards,
Arun

Hi @Arun-Kumar
Thanks, Its working for me

1 Like

Hey @pctripathi

Looks like I gave name instead of ID, this should be corrected as

linkQO.addFilter(Filter.eq("application.id", applicationName));

@Arun-Kumar

It is not good to use context.getObjects particularly in forms as this will cause performance issue when you have large data and infact bring down your system

Hi @iamksatish ,

Thank you for the info! I understand your point regarding the use of context.getObjects in forms. For testing purpose, i have used.

Regards,
Arun

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