- 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-16-2020 03:38 AM
- 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-16-2020 05:17 AM
Yes it worked. Thank you so much
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2020 04:38 PM
You are using an array to push the email ids. If you pass a comma separated value then it will be taken as one value in the array. Please use a different function which will split by commas and return the value. Push each value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2020 01:28 AM
Ok, any sample code you have fo reference?