- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2015 01:16 PM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-09-2015 03:22 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2015 01:37 PM
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 *** |
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2015 01:55 PM
Change your log statement to
gs.log("**User " + gr.name + " has been updated ***");
That should do it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2015 02:10 PM
Thanks Adam, will do, I also found that gr.getDisplayValue() will work too. Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2015 03:16 PM
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