Writing Filter for a multi-valued identity attribute

Which IIQ version are you inquiring about?

8.4

Share all details about your problem, including any error messages you may have received.

We have an multi-valued identity attribute called as testMultiValuedAttribute.

  <entry key="testMultiValuedAttribute">
    <value>
      <List>
        <String>val1</String>
        <String>val2</String>
        <String>val3</String>
        <String>val4</String>
      </List>
    </value>
  </entry>

I need to write a QueryOption and filter and run an Iterator to get all identites that has β€œval1” in the testMultiValuedAttribute.

Can you give a code snippet for this?

Hi @aseelvn07 ,

you can use the following code to filter the users who has given value in the attribute.

 

  import sailpoint.object.QueryOptions;
  import sailpoint.object.Filter;
  import sailpoint.object.Identity;
  import sailpoint.tools.Util;

  import java.util.Iterator;

  import java.util.List;
  import java.util.ArrayList;
  
  List users = new ArrayList();

   String attributeName = "" ; // Set Attribute name 
      
    String value = ""; //Set value 

  QueryOptions options = new QueryOptions();

  Iterator it = context.search(Identity.class, options);

  while (it != null &amp;&amp; it.hasNext()) {
    
    Identity id = (Identity) it.next();

    List values = (List) id.getAttribute(attributeName);  

    if (values != null &amp;&amp; values.contains(value)) {
      
      users.add(id.getName());
      
    }
  }

  Util.flushIterator(it);

  return users;

This will work but not a good solution in terms of memory management. When there 1m+ users in the system, this way can cause memory issue. We need to restrict the result by using QueryOptions

Try this out. Also consider maybe excluding disable accounts or any other values to reduce your total users.

import sailpoint.object.*;

QueryOptions op = new QueryOptions();
op.add(Filter.like("testMultiValuedAttribute", "val1"));
  
Iterator it = context.search(Identity.class, op);

return context.countObjects(Identity.class, op); // Optional if you just want to see your result size

// Insert your while loop logic

Hi @aseelvn07 ,

I have tried using Filter.in() and Filter.contains() approach in QueryOptions , but when I mark an attribute as multi-valued , automatically it is becoming non-searchable attribute in IdentityMappings . So I am getting attribute not found error , therefore I have suggested this approach.

1 Like

@Chathurya
Understood. For this issue, solution is to update hibernate file and DB to create named attribute and then mark it as searchable. Then it will retain the searchable status