- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2024 12:02 PM
I am currently working on an ATF script to test change workflows. As part of the change workflow, the change sends multiple approvals out to members of the CAB group. My understanding is that there aren't any test steps that would allow me to query and approve all the records at once. However, from what I've been seeing, I can run a server side script and should be able to approve all of the records at once. Part of the issue is that I don't know how to get the sys_id of the change record that ATF is creating in order to query the "document_id" field in the "sysapproval_approver" table. Does anyone know how I can accomplish this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-18-2024 05:49 AM
I ended up using a modified version of the script in this article: https://www.servicenow.com/community/developer-forum/atf-accessing-reference-variable-sys-id-in-serv...
Hopefully this helps someone out! Also thanks @Ankur Bawiskar!
(function(outputs, steps, params, stepResult, assertEqual) {
var chgRec = new GlideRecord('change_request');
chgRec.get(steps('033d33be1bc30e10fcfd5395604bcb4a').record_id); // Get the sys_id of the change from the step where it is created
if (chgRec.isValidRecord()) { // Validate the change exists
// gs.log("Change request found with ID: " + chgRec.sys_id);
// Search for approvals related to this change request
var apprRec = new GlideRecord('sysapproval_approver');
apprRec.addQuery('document_id', chgRec.sys_id);
apprRec.query();
// Set all the approvals to approved
var allUpdated = true;
while (apprRec.next()) {
apprRec.state = 'approved'; // Assuming 'approved' is the correct state value
if (!apprRec.update()) {
//gs.log("Failed to update approval record with ID: " + apprRec.sys_id);
allUpdated = false;
} else {
//gs.log("Approval record updated with ID: " + apprRec.sys_id);
}
}
// If all approvals are approved, return true, otherwise return false
if (allUpdated) {
return true;
} else {
return false;
}
} else {
//gs.log("No change request found with the provided ID.");
return false;
}
})(outputs, steps, params, stepResult, assertEqual);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-01-2024 12:16 PM
This thread may help you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-18-2024 05:49 AM
I ended up using a modified version of the script in this article: https://www.servicenow.com/community/developer-forum/atf-accessing-reference-variable-sys-id-in-serv...
Hopefully this helps someone out! Also thanks @Ankur Bawiskar!
(function(outputs, steps, params, stepResult, assertEqual) {
var chgRec = new GlideRecord('change_request');
chgRec.get(steps('033d33be1bc30e10fcfd5395604bcb4a').record_id); // Get the sys_id of the change from the step where it is created
if (chgRec.isValidRecord()) { // Validate the change exists
// gs.log("Change request found with ID: " + chgRec.sys_id);
// Search for approvals related to this change request
var apprRec = new GlideRecord('sysapproval_approver');
apprRec.addQuery('document_id', chgRec.sys_id);
apprRec.query();
// Set all the approvals to approved
var allUpdated = true;
while (apprRec.next()) {
apprRec.state = 'approved'; // Assuming 'approved' is the correct state value
if (!apprRec.update()) {
//gs.log("Failed to update approval record with ID: " + apprRec.sys_id);
allUpdated = false;
} else {
//gs.log("Approval record updated with ID: " + apprRec.sys_id);
}
}
// If all approvals are approved, return true, otherwise return false
if (allUpdated) {
return true;
} else {
return false;
}
} else {
//gs.log("No change request found with the provided ID.");
return false;
}
})(outputs, steps, params, stepResult, assertEqual);