Retrive ResourceObject Owner then set accountgroup owner

I need to retrive resource object owners and then set that owner to accountgroup owner . but in my Obj owners there are list of emails as owner… how do i grab identity from email

Currentcode:

if (accountGroup == null) {
    return null;
}

Identity defaultOwner = context.getObjectByName(Identity.class, "Azure Default Owner");
Identity currentOwner = accountGroup.getOwner();
List ownerList = (List) obj.getAttribute("owners");
if (ownerList == null || ownerList.isEmpty()) {
    log.error("No owners found for obj.");
    return null; 
} else {
    log.error("Owners found: " + ownerList);
}

String objOwner1 = (String) ownerList.get(0);
Identity objOwner = context.getObjectByName(Identity.class, objOwner1);
String displayName = accountGroup.getDisplayName();


if (accountGroup.isRequestable()) {
if (displayName != null && displayName.startsWith("AAD")) {
    if (currentOwner == null) {
        if (objOwner != null) {
            accountGroup.setOwner(objOwner); 
        } else {
            accountGroup.setOwner(defaultOwner);
        }
    }
}
}
else
{
if (displayName != null && displayName.startsWith("AAD")) {
    if (currentOwner == null) {
        if (objOwner != null) {
            accountGroup.setOwner(objOwner); 
            accountGroup.setRequestable(false);
        } else {
            accountGroup.setOwner(defaultOwner);
            accountGroup.setRequestable(false);
        }
    }
}


}

return accountGroup;

so problem is i get email as owner so how do i retrieve identity from that email. This is my log output
Owners ad found: [[email protected], [email protected]]

hi @autorun6464,

you can use context.search() or context.getObjects setting the QueryOption with a filter on the email.

1 Like

use below

Identity identity = context.getUniqueObject(Identity.class, Filter.eq("email",objOwner1);
2 Likes

yup that worked really appreciate that

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