Assignment Rule scripting for assigning to a person and a group for a particular item

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2022 11:22 PM
Hi,
I have an Assignment Rule that assigns different items to an Assignment Group. If one of those items is a particular one, I need not only to assign it to a group, but to a person within that group. I could just make a new Assignment Rule for that particular item, but I have a lot of them already and guess that I can use scripting in the one already assigning items to the group in question. Can anyone help me with a script?
Best regards
Thomas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2022 11:29 PM
Hi,
you can use before insert BR on your table
Ensure you give correct BR condition so that it works only for your particular catalog item
1) get any 1 active member from the group and set it in field
Something like this
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var group = current.assignment_group;
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery("group", group);
gr.addQuery("user.active", "true");
gr.setLimit(1);
gr.query();
if (gr.next()) {
curent.assigned_to = gr.getValue('user');
}
})(current, previous);
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
‎07-06-2022 07:53 PM
Thank you for marking my response as helpful.
If my response helped please mark it correct and close the thread so that it benefits future readers.
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
‎07-05-2022 11:29 PM
Hi Thomas
sample logic for assignment rule script.
if(current.<<field_name>> == 'xyz){
current.assignment_group = 'group sysid';
current.assigned_to = 'assignedto_user_sysid';
}else
{
current.assignment_group = 'group sysid';
current.assigned_to = 'assignedto_user_sysid';
}
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2024 04:59 AM
Hi Rohila,
I am trying to check an if condition to check the login user is member of any group, it is not working. Would you help me to identify the issue.
var grp = gs.getProperty('sn_compliance_case.compliance.case.global.ethics.group');//group sys_id
if (gs.getUser().isMemberOf(grp)) {
current.assignment_group = grp;
} else {
current.assignment_group = "311c1c7fc3f2c110351061ba3c40ddb1"; //group sys_id
}
Thanks
Chandan