Enable dynamic multiple approval in ATF for change requests

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2020 10:57 PM
Hi
I have a requirement where i need to implement an automated test framework (ATF) for change request which has more than 1 approver. I have tried to build this by hard coding the users, impersonating to each approver but i need it to be dynamic so that in future if there are more approvers added or removed, my test case should still work.
Please find the attached screenshot of test steps i wrote. In that, i am impersonating to each approver in steps 10 and 15. I dont want that. Some server script which would read the approver name and impersonate it by itself.
Please let me know if there's any way we can achieve this
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2020 11:24 PM
Hi Chenab,
In step number 5 you have the sys_id of the record which got submitted as Output of that step
Use Server Side Step -> Run Server Side Script
1) you can query sysapproval_approver with approval as the above sys_id and determine the user record for approval
2) Impersonate with the user from above step
3) go to record approve using UI action
4) Again you can use one more Server Side Step and now during query to approval table exclude the user received from step 2 since you already impersonated with that user
check these links:
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2020 11:34 PM
Hi
I have one question, the sys_id we are using will change everytime right?.
i dont understand how to get the sys_id of the create change record in step 5
Let me know
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2020 11:44 PM
Hi Chenab,
that's correct. use below script:
give sys_id of the step number 5 in the place of sysIdOfStep5
First time when you query
(function(outputs, steps, stepResult, assertEqual) {
var record = new GlideRecord('sysapproval_approver');
record.get('sysapproval',steps('<sysIdOfStep5>').record_id);
var approver = record.approver;
if(approver){
outputs.table = 'sys_user';
outputs.record_id = approver;
stepResult.setOutputMessage("Successfully collected user sys_id");
return true;
} else {
stepResult.setOutputMessage("Failed to collect user sys_id");
return false;
}
})(outputs, steps, stepResult, assertEqual);
second time when you query again; exclude the user found from previous step
(function(outputs, steps, stepResult, assertEqual) {
var record = new GlideRecord('sysapproval_approver');
record.addQuery('sysapproval',steps('<sysIdOfStep5>').record_id);
record.addQuery('approver', '!=', steps('<sysIdOfPreviousServerScript>').record_id );
record.query();
if(record.next()){
var approver = record.approver;
if(approver){
outputs.table = 'sys_user';
outputs.record_id = approver;
stepResult.setOutputMessage("Successfully collected user sys_id");
return true;
} else {
stepResult.setOutputMessage("Failed to collect user sys_id");
return false;
}
}
})(outputs, steps, stepResult, assertEqual);
during 3rd time when you write script; exclude both the users as well and so on
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2020 11:49 PM
What if i have 5 approvers....so i need to write this server side script 5 times.
What if in future...there is 1 more approver added or removed, then this test step will fail right?