Workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2023 06:04 PM
Hi everyone,
I had a requirement where I need to exclude users from one specific directory group from receiving notifications from sam subscription table . I need to add this in workflow. I need to create a script and add it in a if condition in a workflow.
Can you pls help me..how can I get this script.
Thanks for the quick help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2023 07:24 PM
So what did you start with and where are you stuck?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2023 07:28 PM
I have created a system property for the directory group and used ismemberof method with system property instead of group name ..will it work...? Can you provide me script if there any
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2023 08:29 PM
HI @mahesh85 ,
I trust you are doing great.
We did something same in our project please find below reference code for the same.
// Replace this with the actual Sys ID of your group
var excludedGroupId = "YOUR_GROUP_SYS_ID";
// Function to check if a user is in the specified group
function isUserInExcludedGroup(userId) {
var grMember = new GlideRecord('sys_user_grmember');
grMember.addQuery('group', excludedGroupId);
grMember.addQuery('user', userId);
grMember.query();
return grMember.hasNext();
}
// This is where you get the user's ID, replace 'target_user_field' with the actual field name
var userId = current.target_user_field;
// Check if the user is in the excluded group
if (isUserInExcludedGroup(userId)) {
// User is in the group, so skip sending notification
// You can return false or handle it as per your workflow logic
return false;
} else {
// User is not in the group, continue with the notification
return true;
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi