- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2022 12:08 AM
Hello,
Can anyone help me achieve this requirement, as I need to auto-populate the assignment group of the incident record if the logged in user is only a member of a single group and that single group should have atleast an itil type?
This is ONLY for when the user creates a new record, assignment group will be autopopulated. Existing records must not be updated.
Appreciate all the help.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2022 03:46 PM
Hi,
I'm glad my reply was Helpful, thanks.
You may want to review current assignment rules to ensure this doesn't fully impact those. Please also ensure if you do have current assignment rules that the owners/requesters of those rules are made aware of what you're doing now, as this will change platform behavior across the board.
With that said, you can review this script and use as you need:
var groupList = gs.getUser().getMyGroups();
var itil = "1cb8ab9bff500200158bffffffffff62"; //verify this matches your group type 'itil' sys_id -- it should, but just check
if (groupList.toString().split(',').length == 1) {
var sGrp = new ArrayUtil().convertArray(groupList);
var gr = new GlideRecord('sys_user_group');
gr.get(sGrp[0]);
if (gr.getValue('type') == itil) {
current.setValue('assignment_group', gr.sys_id);
}
}
You can review the GlideSystem cheat sheet here: https://servicenowguru.com/scripting/user-object-cheat-sheet/
And the GlideRecord API documentation here: https://developer.servicenow.com/dev.do#!/reference/api/paris/server/no-namespace/c_GlideRecordScope...
To tweak and learn as needed.
From here, you'll need to review "when" this business rule runs. If in a before business rule, but you have assignment rules setup on your instance, you may need to set the business rule to an order of 1000 or higher per: https://docs.servicenow.com/bundle/rome-application-development/page/script/general-scripting/refere... -- so that it runs after any assignment rules try to run. Else...this could run BEFORE assignment rules and then those assignment rules overrun this...
Warning, as I mentioned before, this would override other appropriate settings for assignment incidents to groups...so you are changing the entire platform behavior, which could have unintended outcomes. Essentially for any user if they're only a member of one assignment group and that assignment group is of type 'itil'...then the incident would go to their own group. So if a network person was submitting an incident for a laptop issue...for example, this would then route that incident to the network team first...same as if they themselves set the assignment group on the incident as they're creating it...this could change it. Please consider these scenarios and ensure they make sense or review with the process manager/ITIL manager/Helpdesk manager or whatever and consider the negative outcomes.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2022 12:13 AM
Hi,
you can do this using before insert BR
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var groups = new global.ArrayUtil().convertArray(gs.getUser().getMyGroups());
if(groups.length == 1){
current.assignment_group = groups[0];
}
})(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
‎01-09-2022 02:57 PM
Hello
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2022 07:53 PM
The approach I shared is as per the question you asked.
For your further question you can enhance the logic by querying the sys_user_grmember table with your conditions.
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
‎01-10-2022 04:30 PM
Thanks so much for your help. Apologies for modifying my query to another. Thanks so much for all the help.