How can i assign a specific role to a newly created user by ldap import

PriyanshuVerma1
Tera Expert

There is a transform map in servicenow "LDAP USERS" which creates new user or update user in user table. This transform map runs every few minutes in servicenow. There are few transform scripts attached to this transform map.

I was thinking to use onComplete() transform script to add the role to user created via transform map.

But i was also thinking to use a business rule that triggers after an insert action on sys_user table.

This is the business logic :

 

(function executeRule(current, previous /*null when async*/) {
    // Check if the record was created or updated by the LDAP import, so when user is created via ldap transfrom map they have some value in source field starting with ldap
    if (current.sourceSTARTSWITHldap) { 
        // Assign the desired role to the user
        var roleName = 'demo_role'; 
        current.addRole(roleName);
        
    }
})(current, previous);

 

 I would like to have everyone's view on which is the efficient approach performance wise as the ldap transform runs every few minutes.

 

1 ACCEPTED SOLUTION

Hi @PriyanshuVerma1 

Oops! Feel free to choose any of those. 😋 I just provided you with various approaches.

 

Cheers,

Tai Vu

View solution in original post

5 REPLIES 5

Hi @PriyanshuVerma1 

Oops! Feel free to choose any of those. 😋 I just provided you with various approaches.

 

Cheers,

Tai Vu