- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2021 10:12 AM
We currently have a Run Script action in a workflow that dynamically creates a list of approvals based on a list of users. It creates a separate approval for each person in the list. It works quite well. Here is what that code looks like:
//loop through approvers
for (var j = 0; j < apps.length; j++) {
var app = apps[j];
//create approval
var approval = new GlideRecord('sysapproval_approver');
approval.initialize();
approval.state = 'requested';
approval.approver = app;
approval.u_approval_type = 'Cognos: ' + pkg_name + ' Approval';
approval.sysapproval = current.sys_id; //Current is record that requires approval
approval.insert();
}
So "apps" is our list of users to create the approval for.
Now, I want to do the same sort of thing, but with Group Approvals instead. So I want to create multiple Group Approvals for a list of groups that I have. I imagine I could loop through each group, and then loop through each member in the group, and create an approval record for each one, but I think there probably is an easier way, if we can create a Group Approval record instead (and let ServiceNow handle the individual approvals part).
I tried changing the table name in my GlideRecord to "sysapproval_group", and tried a few other changes, but it did not work for me (no errors, it just didn't create anything). Does anyone know how to do something like above to create a Group Approval?
Thanks
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2021 10:23 AM
Hi,
You can try below code for generating grp approval
for (var j = 0; j < apps.length; j++) {
var app = apps[j];
//Group approval
var grApproval = new GlideRecord('sysapproval_group');
grApproval.initialize();
grApproval.setValue('parent', current.sys_id); //parent field refers to task table
grApproval.setValue('assignment_group', app); //apps[j]
grApproval.u_approval_type = 'Cognos: ' + pkg_name + ' Approval';
grApproval.insert();
workflow.info('Group approval has been created ' + grApproval.sys_id);
}
If I have answered your question please mark my response as correct and/or helpful.
Thanks,
Suseela P.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2024 08:43 AM
Hey Suseela,
Thanks for the code! But how can I create multiple "group" approvals if the groups are referencing a table I created that contains the groups, with users assigned to each group?