- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2024 09:38 PM
Good day friends
I'm in a bit of a dilemma and quite confused. I am adding a level of approval in a workflow by copying an existing one that 100% works. On our Change form, we have a list for IT Approvers. I will state that the entire workflow if extremely complex. The code looks at the users in the pick list and converts it to a string. Now I have added some extra levels of approvals and I cannot get these to generate to the IT Approvers prior to reaching the VP, SVP, & CIO.
//querying the approval table and pushing the approver that approved this record.
normalChangeApprovedBy = [];
var normalChangeApprovalGr = new GlideRecord('sysapproval_approver');
normalChangeApprovalGr.addEncodedQuery('sysapproval='+current.sys_id+'^state=approved');
normalChangeApprovalGr.query();
while(normalChangeApprovalGr.next())
{
//this will have the approver it can be AG Manager or AG director
normalChangeApprovedBy.push(normalChangeApprovalGr.approver.toString());
}
answer =[];
var itApprovers = current.u_it_approver;
var splitApprovers = itApprovers.split(',');
for(var i=0; i<splitApprovers.length; i++){
//Checking if the user has allready approved as AG MANAGER or AG Director exculding the senior director of the group if they are part of the IT approval.
if(splitApprovers[i].indexOf(normalChangeApprovedBy) == -1 && splitApprovers[i] != current.assignment_group.u_senior_director)
//if(splitApprovers[i] != current.assignment_group.u_senior_director)
{
answer.push(splitApprovers[i]);//sending approvals
}
}
I have changed the last condition to match the field of these 3 individual. I have taken the entire top portion out of the code. I have redirected the path to a block that I know works. I have placed this new Approval - User action prior to the VP, SVP, & CIO approvals. It marks it as approved and continues on without prompting the approval of the IT Approvers.
The same code is used and works for users.
Am I missing something as to why the same approval would not work for 2 newly added ?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2024 10:08 PM
Hi @scottangehr ,
I trust you are doing great.
Please find the updated version of the script :
// Querying the approval table and pushing the approver that approved this record.
var normalChangeApprovedBy = [];
var normalChangeApprovalGr = new GlideRecord('sysapproval_approver');
normalChangeApprovalGr.addQuery('sysapproval', current.sys_id);
normalChangeApprovalGr.addQuery('state', 'approved');
normalChangeApprovalGr.query();
while (normalChangeApprovalGr.next()) {
// Pushing the approver to the array
normalChangeApprovedBy.push(normalChangeApprovalGr.approver.toString());
}
var answer = [];
var itApprovers = current.u_it_approver;
var splitApprovers = itApprovers.split(',');
for (var i = 0; i < splitApprovers.length; i++) {
var itApprover = splitApprovers[i].trim(); // Trim to remove extra spaces
// Checking if the user has already approved or is excluded
if (normalChangeApprovedBy.indexOf(itApprover) == -1 && itApprover !== current.assignment_group.u_senior_director) {
answer.push(itApprover); // Sending approvals
}
}
// Log the list of IT Approvers to verify
gs.info("IT Approvers to be notified: " + answer.join(', '));
// Return the list of IT Approvers to be notified
answer;
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2024 10:08 PM
Hi @scottangehr ,
I trust you are doing great.
Please find the updated version of the script :
// Querying the approval table and pushing the approver that approved this record.
var normalChangeApprovedBy = [];
var normalChangeApprovalGr = new GlideRecord('sysapproval_approver');
normalChangeApprovalGr.addQuery('sysapproval', current.sys_id);
normalChangeApprovalGr.addQuery('state', 'approved');
normalChangeApprovalGr.query();
while (normalChangeApprovalGr.next()) {
// Pushing the approver to the array
normalChangeApprovedBy.push(normalChangeApprovalGr.approver.toString());
}
var answer = [];
var itApprovers = current.u_it_approver;
var splitApprovers = itApprovers.split(',');
for (var i = 0; i < splitApprovers.length; i++) {
var itApprover = splitApprovers[i].trim(); // Trim to remove extra spaces
// Checking if the user has already approved or is excluded
if (normalChangeApprovedBy.indexOf(itApprover) == -1 && itApprover !== current.assignment_group.u_senior_director) {
answer.push(itApprover); // Sending approvals
}
}
// Log the list of IT Approvers to verify
gs.info("IT Approvers to be notified: " + answer.join(', '));
// Return the list of IT Approvers to be notified
answer;
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2024 04:39 AM
Thank you so much for your help! That worked.
Kind regards
Scott