In ATF, How to impersonate specify a member of a certain group who approves Change Request

Jayesh1
Giga Contributor

Hi,

In order to test a Change workflow I would like to have a step to impersonate a member of a certain group that can approve the change request. I would like to make it generic so that any member of a group can be selected. Has anyone tried this? 

 Please provide me "Run Server Side Script" for Change request.

Jayesh.

1 ACCEPTED SOLUTION

Hi Jayesh,

So once change request is submitted 6 approvals are generated for it. you need to do that one by one. 

So you are saying you need to impersonate six times and every time different user should be there in impersonation

Try this; I believe you need to run this 6 times

1) in the 1st run server side script step directly query sysapproval_approver table to get the approver

2) from the 2nd run server side script step onwards add the query of state is in requested so that it won't pick the 1st record which got approved

and same for other scripts

Sample below

Note: this will only work when you know there will be 6 approvals; consider in future that approval goes to 8 users then it will fail

This is non-tested

 

(function(outputs, steps, stepResult, assertEqual) {
// add test script here

// give here the step sys_id for submit form of change request

var changeRecordSysId = steps('sys_id_of_step').record_id; 

var gr = new GlideRecord("sysapproval_approver");
gr.addQuery('state','requested');
gr.addQuery('sysapproval',changeRecordSysId);  
gr.query();
if(gr.next()) {

outputs.table = 'sys_user';

outputs.record_id = gr.approver;

stepResult.setOutputMessage("Approver user found " + gr.approver.name);

stepResult.setSuccess();

return true;

}

sharing links as well for help

https://community.servicenow.com/community?id=community_question&sys_id=0661776adbb3234423f4a345ca96...

https://community.servicenow.com/community?id=community_question&sys_id=5940b2fadbef63809a64e15b8a96...

Regards
Ankur

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

5 REPLIES 5

Hi, I have the similar query... Could you please look into that. Its really urgent and not able to get the solution.  Please find the link below

 

https://community.servicenow.com/community?id=community_question&sys_id=9526718c1b836450ed6c9979b04b...