- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2022 01:47 AM
Hello All,
Catalog Item having 2 fields requested for and assignment group here I want "If requested for is a member of assignment group no need to send approval else approval needed
If script in workflow
answer = ifScript();
function ifScript() {
var reqFor = current.variables.requested_for.toString() ;
if(reqFor.isMemberOf(current.variables.assignment_group.toString())){
return 'yes'; //no approval
}
return 'no';//trigger for approval
}
Above code is not working shows error in script..
Thanks
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2022 02:48 AM
Hi,
Update your code as below.
answer = ifScript();
function ifScript() {
var userObj = gs.getUser();
var reqFor = userObj.getUserByID(current.variables.requested_for);
var grp = current.variables.assignment_group;
workflow.info('User = '+reqFor+' Group = '+grp);
if (reqFor.isMemberOf(grp)) {
workflow.info('YES');
return 'yes'; //no approval
}
workflow.info('NO');
return 'no'; //trigger for approval
}
Please mark the answer as correct/helpful based on impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2022 02:04 AM
Hi,
You would need a combination of Script Include and the current workflow script which you have written as below to handle this:
1) Create a Script include and use the script as below:
var checkMember = Class.create();
checkMember.prototype = {
initialize: function() {
},
validateMember : function(groupName,requestedFor){
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group',groupName);
gr.addQuery('user',requestedFor);
gr.query();
if(gr.next()){
return true;
}else{
return false;
}
},
type: 'checkMember'
};
Now in your IF Activity in workfow used below:
answer = ifScript();
function ifScript(){
var check = new checkMember().validateMember(current.variables.assignment_group,current.variables.requested_for);
}
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2022 02:07 AM
So in above script Is Request for is a member of Selected Group on Form it will return as True and you can connect the Yes line from IF Block activity, else if not a member then it will return false and you can connect the No line from workflow activity.
Screenshot below for both code for reference:
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2022 03:04 AM
Hi,
Tried with above code not working..
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-12-2022 03:45 AM
What was the issue which you were facing? Please make sure to also reply back with the issue you are facing to assist further.
Also, as a best practice by using a Script Include as instructed above, it would have given an ability to use the same function anywhere else when there is a similar requirement by just calling a single line of code as below and passing the correct parameter and not every time writing several lines of Glide Record all the time.
var check = new checkMember().validateMember(current.variables.assignment_group,current.variables.requested_for);
Ultimately it's up to you to decide which ever method you want to go with.
Regards,
Shloke
Regards,
Shloke