Filter Account by last name from Application

Hi,
I have created a form with two fields where in first field we get application name and in second field we get the list of accounts present in that Application.
I want to display only accounts in the second field which have a manager assigned and accounts last name is NPIdentity. I have created both the filters but not sure if I can add two allowed values attribute. And when merging both its not working. Below are both the codes.

Code for getting accounts

 <Field displayName="Select" dynamic="true" name="Field_6" postBack="true" required="true" type="Application"/>
    <Field displayName="Select Account" 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>

Code for applying filter

 import sailpoint.object.*;
            List identityList = new ArrayList();
            QueryOptions qp = new QueryOptions();
            qp.addFilter(Filter.eq("lastname","NPIdentity"));
            Iterator it = context.search(Identity.class,qp);
            while ( it.hasNext() ) { 
            Identity identity = (Identity)it.next();
            //if(null != identity){ 
            if(null != identity &amp;&amp; identity.getManager() != null) { 
            identityList.add(identity.getAttribute("workerid"));
            }
            }
            return identityList;

You can try with below code

 import sailpoint.object.*;
 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;
import sailpoint.api.IdentityService;
 
            List accountNames = new ArrayList();
			List identityList = new ArrayList();
			IdentityService is = new IdentityService(context);
            String applicationName = form.getField("Field_6").getValue();
            Application App = context.getObjectById(Application.class, applicationName);
            
            QueryOptions qp = new QueryOptions();
            qp.addFilter(Filter.eq("lastname","NPIdentity"));
            Iterator it = context.search(Identity.class,qp);
            while ( it.hasNext() ) { 
            Identity identity = (Identity)it.next();
            if(null != identity @and identity.getManager() != null) { 
            identityList.add(identity);
            }
            }
			for(Identity id:identityList){
			
			List links= is.getLinks(id,app);
			if(null !=links @and links.size()>0){
			for(Link link:links){
			if(!link.isDisabled())
			accountNames.add(link.getNativeIdentity());
			}
			
			}
			
			}
			
            
			return accountNames;

Hi @Arun-Kumar
Seems like filter for NPIdentity is not working here. All accounts are visible which are present in the application.

I have checked, it is returning based on the filter.
update the code as below and check

List links= is.getLinks(id,App);

Hi @Arun-Kumar
result is the same.
Okay can something like in this code I get.

import sailpoint.object.*;
            List identityList = new ArrayList();
            QueryOptions qp = new QueryOptions();
            qp.addFilter(Filter.eq("lastname","NPIdentity"));
            Iterator it = context.search(Identity.class,qp);
            while ( it.hasNext() ) { 
            Identity identity = (Identity)it.next();
            //if(null != identity){ 
            if(null != identity &amp;&amp; identity.getManager() != null) { 
            identityList.add(identity.getAttribute("workerid"));
            }
            }
            return identityList;

here we are getting All the identities which are in sailpoint with lastname as NPIdentity.
Can it just be editied in a way so that instead of showing all the identities it shows only those identities present in the Application selected above.

I provided the code for that purpose. Could you please share the dropdown values for the “Select Account” field?

Actually I am getting all the accounts under that Application. the lastname filter of the code is not working somehow I suppose because when I am using above codes which I mentioned, they are working individually but not together.
I have checked and verified the identites also.

Also when I write the worker ID in “Select Account” field I am not able to search the account.

Hi @Arun-Kumar
It was a problem from my end. Its working.

1 Like

Can you suggest a way that I can search inside it if I know the ID.

Figured it out. Instead of getNativeIdentity I had to use getDisplayName

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