Check for uniqueness in a multivalued attribute

Which IIQ version are you inquiring about?

8.4p2

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

hey everyone,

so i have this beanshell code that check for my email prefix uniqueness by searching IQ attributes and this works fine:

    		QueryOptions qo2 = new QueryOptions();
        qo2.addFilter(Filter.like("email", mailprefix));

        QueryOptions qo = new QueryOptions();
        qo.addFilter(Filter.like("OIDmailPrefix", mailprefix));
 


        List<Identity> identities = context.getObjects(Identity.class, qo);
				 List<Identity> emails = context.getObjects(Identity.class, qo2);

        if (!identities.isEmpty() || !emails.isEmpty() ){      
            isUnique = false;
        } else {
            isUnique = true;
        }


    return isUnique;

now i need to seach an additional attribute that is multivalued for that same uniqueness and when i try to it the same way it fails.

i tried it this way :

QueryOptions qo3 = new QueryOptions();qo3.addFilter(Filter.contains(“oidNplexInternetMailAddress”, mailprefix)); //oidNplexInternetMailAddress is multivalued
List<Identity> alias = context.getObjects(Identity.class, qo3);

and then adding it to my if condition but the qo3 is failing

any ideas what i’m doing wrong ?

thanks for the help !

What is the error you are getting, are you sure oidNplexInternetMailAddress this is a searchable attribute?

Hey satish,

well when i select Multi-Valued in the Identity Mappings where i created the attribute, i cannot select the Searchable Checkbox Anymore, as for the error, nothing in the interface except i can see it’s not doing the job when i add this code…

Multi-valued attributes are searchable by default, but they are stored separately in the database so you have to join your query. Just another tip, don’t insert new multivalued attributes via debug, it won’t get added properly and you won’t get results.

Hope this helps:

import sailpoint.api.*;
import sailpoint.object.*;
import sailpoint.search.ExternalAttributeFilterBuilder;

String mailprefix = "";

Filter filter = ExternalAttributeFilterBuilder.buildOrFilter("IdentityExternalAttribute", "id", "oidNplexInternetMailAddress", Util.csvToList(mailprefix), "EQ");

QueryOptions qo = new QueryOptions();
qo.add(filter);
qo.setResultLimit(1); // You only need to find one to know it's not unique

List identities = context.getObjects(Identity.class, qo);

return identities.isEmpty(); // true is unique

You have the option to use buildAndFilter (looks for all values in the list) or buildOrFilter (looks for any values in the list). There’s also constants in case you would rather write it like this:

ExternalAttributeFilterBuilder.buildOrFilter(ExternalAttributeFilterBuilder.IDENTITY_EXTERNAL, ExternalAttributeFilterBuilder.IDENTITY_JOIN, "oidNplexInternetMailAddress", Util.csvToList(mailprefix), "EQ");

5 Likes

Hello sunny

thanks a lot this works perfectly

1 Like

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