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

How could I auto-generate a request and auto-populate variables when a user is deactivated?

neil_b
Tera Guru

I have a record producer that lets users indicate whether to add a new software license, renew a software license, or revoke a software license and users would submit the request for approval. If they are renewing or revoking, users have the ability to indicate which previous request # they are renewing or revoking so that the requests are associated with each other.

 

I would like the system to function where, when a user is deactivated, automatically generate a request and auto-populate the variables with certain values such as, "type of request (revoke license)", "user to be revoked (user a)", "previous request (request001)", etc. It would keep it in a draft state and send an email to the assignment group of the previous request, notifying them that a request has been generated and to submit it for completion. 

 

Is this something that can be accomplished with ServiceNow? If so, can I have some guidance? 

 

I was thinking that a business rule would start it off, triggering when a user gets deactivated but from here, I'm not sure where to go. 

3 REPLIES 3

jcmings
Mega Sage

This could be done in a business rule, sure... you'd set up a on update BR on the sys_user table when "Active" changes to "false." You'd have to script it out, but it would look something like this...

 

 

var gr = new GlideRecord('table'); //wherever the requests are stored
gr.addEncodedQuery('requested_for', current.sys_id); //requested_for or whatever field the subject person is stored in
//then add in any other conditions that would match the user to the previous request
gr.query();
if (gr.next()) {
var oldAssignmentGroup = gr.assignment_group;
}

var gr2 = new GlideRecord('table'); //table that you want to create a request on
gr2.newRecord();
gr2.type_of_request = 'value'; //whatever the value of 'revoke license is'
gr2.user_to_revoke = current.sys_id; //current sys_id represents the current user that just got deactivated;
gr2.state = 'draft'; //not sure if you want this to be created in the Draft state or not actually created
//other fields you want to set
gr2.assignment_group = gr.assignment_group;
var newRecordSysId = gr2.insert();

//not sure if that new record triggers the email you want, but otherwise you can initiate an event
//if you want to go the event route, you need to add it to the Event Registry
//and you also need to create a notification that triggers on the event; parm1 and parm2 will contain recipients
gs.eventQueue('send_email_event_name', newRecordSysId, current.sys_id, oldAssignmentGroup);

 

 

Thanks @jcmings I'll give this is a shot and report back to you! I appreciate the swift assistance! 

@neil_b  I'll also add - you might find this a lot easier in a Flow! I got sucked into trying to code it for you, and totally neglected that this would be a lot easier to accomplish in a flow.