The CreatorCon Call for Content is officially open! Get started here.

Deactivate user when not found on the LDAP import

Mark_Bailey
Mega Guru

Greetings

Our LDAP management seems to be a lot different than most companies. The out of box deactivation script is looking for the users to go into a specific OU of have a specific field marked.   I need a much simpler script. IF a user is not found on the AD import and already exist as active on ServiceNow AND was initially imported via LDAP (User Source is not blank) , then deactivate.

I am hoping someone might have something very similar I can do some minor adjusting to.

Out of Box on before deactivated scriptnot being used (Part of the LDAP import)

var ctrl = parseInt(source.u_useraccountcontrol, 10);

ctrl = ctrl.toString(16);

//The relevant digit is the final one

//A final hex digit value of '2' in 'ctrl' means disabled

if (ctrl.substr(-1) == "2") {

    target.active = false;

    target.locked_out = true;

    if (action == 'insert')

          ignore = true;

} else {

    //Optional: Reactivate and unlock the user account

    //target.active = true;

    //target.locked_out = ctrl.substr(-2, 1) == "1";

}

28 REPLIES 28

Yes you are correct.



The user is active on SN and deactivated from AD in my case.


I was looking at creating a new server while implementing the script and found this Find inactive LDAP accounts using the lastRefresh time, i like it better than the script provided on this thread as it gives more control over what is happening.


Nilanjan1
Mega Sage

Hello All, 

 

This is really helpful. However, when I try to run the script in the background scripts it seems that there is a declaration error in the following line. 

var importSet = import_set.number; -- import_set not defined. 

Did someone get into the same issue?

Background scripts won't have access to the import_set object as written. You'll need to set the import_set.number value directly as well as any other fields pulled from the import_set object if you want to run this in Background scripts.

Michael