Client script to Assign Group automatically
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-16-2017 08:26 AM
Hi community
I want to auto-assign automatically the Assignment Group(Hardware Group) based on the Business Service( hardware) that is selected when a user submit a new incident from the Service Portal
I have another Business Service( software) that when a Incident is submitted, they are assigned automatically to "Software Group", it works fine, but I don't know which script handles this.
So, I created this Client Script I found in the community, but something keeps setting all Incidents to "Software Group", I don't know if I am doing something wrong.
function onSubmit() {
//Type appropriate comment here, and begin script below
var bs= g_form.getReference('Hardware', setAssignmentgroup);
function setAssignmentgroup() {
if (bs)
g_form.setValue('Hardware group', bs.assignment_group);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-16-2017 09:42 AM
Hi Lex,
Small correction in below call back function line, please pass the reference as an argument.
function setAssignmentgroup(bs) { //reference is passed into callback as first arguments
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-16-2017 05:21 PM
Thanks, my code looks like below, but it isn't still working...
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var bs= g_form.getReference('business_service', setAssignmentgroup);
function setAssignmentgroup(bs) {}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-16-2017 06:06 PM
Can you try with.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var bs= g_form.getReference('business_service', setAssignmentgroup);
function setAssignmentgroup(bs) {
if (bs.assignment_group != '')
g_form.setValue('assignment_group', bs.assignment_group);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-16-2017 08:45 PM
Hi Lex,
If i am not wrong you want to set the assignment group based on your business services.
if i see your script you did not pass the business service field name and assignment group field name.
eg: if you have selected Blackberry as business service then you want to set hardware group. if this is your requirement then please try with script below.
i tested with blackberry business services and assigned hardware group in assignment group field.
you just need to copy the sys_id of business services (blackberry) in my case. and you want to assign some particular assignment group then you also need to copy the sys_id of assignment group.
below screenshot will help you to how will you copy the sys_id of business services and assignment group.
Business service(i tested with blackberry) .
same way you can copy the sysid of your particular assignment group.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
g_form.setValue('assignment_group','');
return;
}
//Type appropriate comment here, and begin script below
var check= g_form.getValue('business_service');
if(check=='27d3f35cc0a8000b001df42d019a418f') //here sys_id i have for blackberry
{
g_form.setValue('assignment_group','8a5055c9c61122780043563ef53438e3'); //sys_id of hardware group.
}
}
I tested and it works fine at my end .
Hope it will help you
Let me know if you have any further question.
GlideForm (g form) - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-16-2017 10:35 PM
Please Check if there is any Assignment Rule configured on the incident table. Its under System Policy. This rule always works on the insertion of a record and only one rule with lower order will execute in case of same condition. You can achive this solution by creating a assignement rule as well where you can put conditions, order and set the assignment group.
Defining Assignment Rules - ServiceNow Wiki
Regards,
Souren