- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2020 04:21 PM
Hi,
Just encountered this simple question, how to set approvers dynamically based on oe catalog variable. I tried to modify the script in multiple ways but not able to fix it. So we have a custom table where we have stored all those servers. In the catalog item form, we have a select box variable that refers to that table. Now the approval has to go to Email address field of the same table stores the email Ids with comma separated value. I am using the below code in approval activity, but it's not triggering the approval but it's going inside while loop. Any idea why is it skipping the approval record and moving to the next stage?
I am using the below script in advanced script option:
Any help will really be appreciated.
Thanks & Regards,
Madhu
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2020 04:32 AM
Hi,
why you are using current object at line 19 and 20
Do you want User Approvals for the email addresses? if you have group email addresses then are you saying you want approvals to go to the group members as well?
if yes then please use below script
// your top code as it is
var emailAddressList = appRec.u_emailaddress.toString();
var userRec = new GlideRecord('sys_user');
userRec.addQuery('email', 'IN', emailAddressList);
userRec.query();
while(userRec.next()){
answer.push(userRec.sys_id.toString());
}
// now push group members to array
var groupRec = new GlideRecord('sys_user_group');
groupRec.addQuery('email', 'IN', emailAddressList);
groupRec.query();
while(groupRec.next()){
var members = new GlideRecord('sys_user_grmember');
members.addQuery('group', groupRec.sys_id);
members.query();
while(members.next()){
answer.push(members.user.toString());
}
}
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
Regards
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
06-14-2020 04:34 PM
Rather than adding users email id. You need to push user ids of users or groups.
answer.push(appRec.sys_id.toString())
Muhammad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2020 05:27 PM
Hi Madhu, Did you get a chance to try above?
Muhammad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2020 01:28 AM
Yes checked,.as the table is customed and the email address field is just a string field which stores the approvers mail address with comma separated value. How to get the approval goes to all those email address?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2020 02:05 AM
Hi Madhu,
So you have comma separated email addresses in that u_emailaddress field
for approvals to work it requires user sys_ids or group sys_ids
so you need to query sys_user table for those email addresses and then set store the user sys_id in the answer array one by one
// your top code as it is
var emailAddressList = appRec.u_emailaddress.toString();
var userRec = new GlideRecord('sys_user');
userRec.addQuery('email', 'IN', emailAddressList);
userRec.query();
while(userRec.next()){
answer.push(userRec.sys_id.toString());
}
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader