Approval Query from Workflow

Joshuu
Kilo Sage

Hi All,

 

I have a field on the change form as "Maintenance window" which is list type and reference to schedule entries table in ServiceNow.

 

And we need to create an approval for primary and secondary contacts from these schedules in the change.

 

So, I am creating approvals by using approval-user activity in the workflow and through below advanced script.

var approvers = [];

if (current.u_maintainence_window) {
var maintenanceWindows = current.u_maintainence_window.split(',');

var gr = new GlideRecord('cmn_schedule_span');
gr.addQuery('schedule', 'IN', maintenanceWindows);
gr.query();

while (gr.next()) {
if (gr.schedule.u_pri_contact) {
approvers.push(gr.schedule.u_pri_contact.toString());
}
if (gr.schedule.u_ec_contact) {
approvers.push(gr.schedule.u_ec_contact.toString());
}
}
// Remove duplicates
var uniqueApprovers = [];
for (var i = 0; i < approvers.length; i++) {
if (uniqueApprovers.indexOf(approvers[i]) === -1) {
uniqueApprovers.push(approvers[i]);
}
}
approvers = uniqueApprovers;
} else {
gs.print('No maintenance windows found.');
}
// Return approvers
answer = approvers;


Here, approvals are getting created but whenever one is approved remaining are becoming no longer required.

But we need to go by maintenance window wise. If primary approval is approved from "B2C Web Maintenance Window" schedule, then secondary should be no longer required and vice versa. But here it is making all the other approvals also no longer required.

 

Do I need to change anything in the script?

 

Please assist.

 

Thanks & Regards.

3 REPLIES 3

Anand Kumar P
Giga Patron
Giga Patron

Ho @Joshuu ,

 

The issue is with the Approval User activity, which treats all approvals as one group, marking others “No longer required” when one is approved. To handle approvals maintenance window-wise, create separate approval groups for each window and add groups one group approved other not required viceversa.

 

Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand

 

 

Hi @Anand Kumar P ,

 

So, do we need to create groups for each window? then in future if they change primary or secondary contact in the schedule we also need to change in the groups as well correct?

Hi @Joshuu ,

 

Yes correct, if there is any change in contacts in schedule you can write scrip to automate to add to groups.

 

Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand