Help with script to set assignment group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2022 11:51 AM
Hello,
I need a bit of help with my script. This is an on load client script on the incident table where I need to check if the user that raises a new record is part of any itil groups and if he is (the user will only be part of 1 itil group, not more), then set the assignment group to that.
Now bear in mind I'm new to this and this what I've come up with:
function onLoad() {
var usr = g_form.getValue('caller_id'); //get sys id of user
var gr = new GlideRecord('sys_group_has_role');
gr.addQuery('role', 'itil'); //pull groups that have itil role
gr.query();
while (gr.next()) {
var grpID = []; // I want the groups to be put into an array
grpID.push(gr);
jslog('Groups with itil ' + grpID);
var mbr = new GlideRecord('sys_user_grmember');
mbr.addQuery('user', usr);
mbr.addQuery('group', grpID[0]); //here I want to check if user is part of the first itil group for example
mbr.query();
if (mbr.next()) {
jslog('User part of itil group ' + grpID[0]);
g_form.setValue('assignment_group', grpID[0]); //if user is part of itil group, set that group as assignment group - I know this is wrong though but I can't see any logs so not sure what type of data grpID is
}
//else .. here I need to iterate through the rest of the groups
}
}
Unfortunately, I can see the logs that I've put there so I'm sure a lot of things are wrong with my logic here. If there is a simpler way to do this, please advise.
Thanks
- Labels:
-
Multiple Versions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2022 11:57 AM
Hi,
It's not recommended to use GlideRecord within client script due to performance implications, etc.
It's recommended to please use GlideAjax to communicate with the server and retrieve that information, which can then be returned to the client, so you can do 'x'.
Please review this cheat sheet for assistance: https://community.servicenow.com/community?id=community_article&sys_id=9f7ce2e1dbd0dbc01dcaf3231f961...
What you're using only sets the assignment group in the client, but then the user could change it. You may want to review using "assignment rules" or a business rule instead...
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
‎02-24-2022 11:59 AM
Also duplicate question that you've posted: https://community.servicenow.com/community?id=community_question&sys_id=2b58320edb758550ae8125091396...
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
‎02-24-2022 12:53 PM
Thank you for the tips Allen. I did post another question on this but the answer didn't give me enough information on how to achieve this and no one else was picking it up. Should I delete the old or is there a way to 'promote' it in order to be seen by more users before I post the same question again?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2022 01:01 PM
Hello,
You would edit the question to help make it more clear (perhaps it wasn't described enough for people to help) and then just reply to it to ask again for assistance.
Creating a new question after 3 days isn't really necessary.
You can see the question text from that question and now this one and it's changed a bit, you've added more information.
If you are saying their reply didn't help you, you could always respectfully reply and ask for more assistance. You didn't even reply or do anything there.
What
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!