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

Allen Andreas
Administrator
Administrator

Hello,

In my opinion, I don't think you've given us enough to fully help you, much less enough to just give you script without getting more details.

At what point in the incident lifecycle are you talking about populating the group?

If later in the incident lifecycle...what if the record already has a group (as could be done via assignment rules and such).

At no point did you say this was on the insert of the record, so I'm unsure how anyone would know that other than just guessing.

It may be appropriate to consider giving a bit more information and also think through what you need help with. As your original question didn't list the "itil" type group condition.

Please give more information as your post lacks a few important details.

Please mark reply as Helpful, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hello, thanks for your input. I have updated my query as per your suggestion. 

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!

Hello, thanks for this answer and views. Though the script is not working on my end, it returns null on this part gr.getValue('type') == itil

Hi,

Thanks. Please see my edited reply above with slightly adjusted script.

Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!