- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2019 08:14 PM
Hi all,
I have a requirement, where on a catalog end user submission form we have two fields 'caller' and 'group' fields which has to be filled by the user.
Now the requirement is in the work flow we need to check if the user in the caller is part of the group value in the variables. If the user is part of that group we need to trigger approvals in the workflow, other wise skip the approval.
Please suggest. Thanks in advance.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2019 09:12 PM
Hi Kishan
Use if activity and below script; the yes output would go to approval activity; the no output would go to the activity which is next to approval in workflow
Ensure you use proper user and group variable in below script
answer = ifScript();
function ifScript(){
var userObject = gs.getUser().getUserByID(current.variables.userVariable);
if(userObject.isMemberOf(current.variables.groupVariable))
return 'yes';
}
else
return 'no';
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
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
09-17-2019 08:39 PM
Hi Kishan,
Use run script form workflow
and please find below link
https://community.servicenow.com/community?id=community_question&sys_id=c7c7d73fdb0033c0fff8a345ca96194b&view_source=searchResult
Thanks
Sayali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-17-2019 09:12 PM
Hi Kishan
Use if activity and below script; the yes output would go to approval activity; the no output would go to the activity which is next to approval in workflow
Ensure you use proper user and group variable in below script
answer = ifScript();
function ifScript(){
var userObject = gs.getUser().getUserByID(current.variables.userVariable);
if(userObject.isMemberOf(current.variables.groupVariable))
return 'yes';
}
else
return 'no';
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
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
09-18-2019 12:12 AM
I have used the below script and it is not working as expected.
The support group is not a reference field but a single line text field. It will be automatically updated using a script include in the back ground checking on the CI.
answer = (function(current) {
var supportGrpSysId = current.variables.support_group;
var userSysId = current.variables.requested_for_name.toString(); //assumes requested_for is reference field.
/*Determine if the requested_for user is part of the support group assigned to job*/
var grGrpMem = new GlideRecord("sys_user_grmember");
grGrpMem.addQuery("group",supportGrpSysId);
grGrpMem.addQuery("user",userSysId);
grGrpMem.query();
if (grGrpMem.next()) {
return "yes"; //return "yes" if they are part of the group
}
else {
return "no"; //return "no" if they are not part of the group
}
})(current);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2019 12:19 AM
Hi Kishan,
First of all is this for catalog item? if yes then are those 2 variables a string or reference
So is the user variable also a string field or a reference to sys_user table?
so group field is string field where users will enter group name
so you can use below script
answer = ifScript();
function ifScript(){
var userObject = gs.getUser().getUserByID(current.variables.userVariable);
// isMemberOf can take group name as well
if(userObject.isMemberOf(current.variables.groupVariable))
return 'yes';
}
else
return 'no';
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader