How to autopopulate assignment group if the logged in user is a part of a single group

Evren Yamin
Tera Contributor

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.

1 ACCEPTED SOLUTION

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!

View solution in original post

10 REPLIES 10

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hello @Ankur Bawiskar , thanks for this. Is there a way to make this more specific, like to look for groups that has an itil type where the current logged in user is a member of? It will only autopopulate when the current logged in user is a member of a single group and that group has an itil type. 

@Evren Yamin 

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Thanks so much for your help. Apologies for modifying my query to another. Thanks so much for all the help.