- 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-18-2019 02:27 AM
Yes, this is on a catalog item.
requested for user is a reference variable.
Group is a single line text variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2019 02:30 AM
have used the below script but it is not working,
answer = (function(current) {
var userObject = gs.getUser().getUserByID(current.variables.requested_for_name);
if(userObject.isMemberOf(current.variables.supprt_group)){
return "yes";
}
else{
return "no";
}
})(current);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2019 02:33 AM
can you try now.
answer = (function(current) {
var userObject = gs.getUser().getUserByID(current.variables.requested_for_name);
if(userObject.isMemberOf(current.variables.supprt_group.getDisplayValue())){
return "yes";
}
else{
return "no";
}
})(current);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2019 02:38 AM
make sure the variable name is fine.
support_group

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2019 02:45 AM
Hello,
please try below code:
answer = ifScript();
function ifScript(){
var userObject = current.variables.getValue('userVariable');
if(userObject.isMemberOf(current.variables.getDisplayValue('groupVariable')))
{
return 'yes';
}
else
{
return 'no';
}
}
Regards,
Sanket