How to Reactivate User id If it is inactive??????

Divya K1
Tera Guru

Hi,

We have a rule to deactivate ids individuals are trying to use the "Add New User " (catalog item)  in Catalog to get themselves "reactivated".  This is an automated action orchestration and the system is closing the requested item stating that it has created the new id HOWEVER the user id cannot be used as its not setting active=true and locked out=false and password reset=false which is causing issues.

So, how to reactivate user id again. Can any one guide me on this???

Thanks,

 

5 REPLIES 5

ersureshbe
Giga Sage
Giga Sage

Hi, Question -

The deactivated account already there and you want to activate the account with the help of 'Add New User' catalog item.

If yes, should modify your code in the workflow ie.you validate that user id present or not.

If present you should activate else you should create the account.

Regards,

Suresh

Regards,
Suresh.

Hi Suresh,

Thanks for your reply,

i  see that there is a script (RQF Ffullfillment task script for a catalog item ) return to create new user id in servicenow... Here is the script.. Can you help me where i can update in the script??

help me with the script to check if user exists and update in the script to set active=true and locked out=false and password reset=false

function(current) {
//code here - return true or false - do not add characters outside the function
targetemail = current.variables.Email.toString();
//company_onboarding
var check = new GlideRecord('sys_user');
check.addEncodedQuery('email=' + current.variables.Email.toString());
check.query();
if (check.hasNext()) {
current.work_notes = "Create failed; user id with email address " +
current.variables.Email.toString() +
" already in database.";

} else {
gr = new GlideRecord('sys_user');
gr.newRecord();
gr.first_name = current.variables.First_name.toString();
gr.last_name = current.variables.Last_name.toString();
gr.email = current.variables.Email.toString();


}

Divya K1
Tera Guru

Hi All,

Can any one guide me on this???

Sagar Agarwal
Mega Guru

Hi Divya,

 

here is the updated script based on your suggestion:

function (current) {
    //code here - return true or false - do not add characters outside the function
    var targetEmail = current.variables.Email.toString();
    //company_onboarding
    var check = new GlideRecord('sys_user');
    check.addEncodedQuery('email='+ targetEmail);
    check.setLimit(1);
    check.query();
    if (check.next()) {
        current.work_notes = "Create failed; user id with email address " +
            targetEmail +
            " already in database.";

        // Unlock existing user account
        check.active = true;
        check.password_needs_reset = false;
        check.locked_out = false;
        check.update()

    } else {
        // Create new account if user account with email does not exist in system
        gr = new GlideRecord('sys_user');
        gr.newRecord();
        gr.first_name = current.variables.First_name.toString();
        gr.last_name = current.variables.Last_name.toString();
        gr.email = targetEmail;
        gr.active = true;
        gr.password_needs_reset = false;
        gr.locked_out = false;
        gr.insert();
    }
}

 

If my answer helped you in any way, please then mark it as helpful.

Kind regards,

Sagar