Catalog Item to set user values

Baggies
Kilo Guru

I receive numerous requests to manually activate user records in ServiceNow, ie set active=true, and locked_out=false, so that HR can complete termination tasks. They need the account active for a short amount of time. The user record will get updated anyway on the next import/update from AD.

I would like to do it from a catalog item, which HR can initiate themselves, so that I have a record. I created an item, and a workflow to go with it. The workflow activity (definition= run script) is where I am coming unstuck.

The variable on the item is 'activate_user', a reference to the sys_user table.

In the run script workflow activity, I would like to have the script activate the user, specified in the activate _user variable.

The script should be simple shouldn't it? Something like:

var user = current.variable_pool.activate_user;

user.active=true;

user.locked_out=false;

user.update();*/

Or would I have to build a query to query the user table for the user first? Also, I think there may be an ACL involved to, to allow HR to update the user record. Maybe there is a better solution? A custom application? Appreciate any help. Thanks

1 ACCEPTED SOLUTION

Your variable contains the sys_id of the User record.   You will need to use something like:


onSubmit(){


var caller = g_form.getReference('caller_id', doAlert); // doAlert is our callback function


}


function doAlert(caller) { //reference is passed into callback as first arguments


    alert (caller.name +   " is active now ");


}




See Wiki on getReference:


GlideForm (g form) - ServiceNow Wiki


View solution in original post

7 REPLIES 7

Baggies
Kilo Guru

I think I have it, I used this script:




var gr = new GlideRecord('sys_user');


gr.addQuery ("sys_id", current.variable_pool.activate_user);


gr.query();


while (gr.next()) {


          gr.locked_out = false;


    gr.active=true;


          gr.update();


  gs.log("**User " + gr + " has been updated ***");


  }      



except my log entry says -


Information**User [object GlideRecord] has been updated ***

Change your log statement to


gs.log("**User " + gr.name + " has been updated ***");


That should do it.


Thanks Adam, will do, I also found that gr.getDisplayValue() will work too. Cheers


Baggies
Kilo Guru

Works just fine, although I tried to add an alert like this, but I can only get the sys_id to display.



function onSubmit() {


      var user = g_form.getValue('activate_user');


      alert (user.name +   " is active now ");


}



will keep on trying