- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2021 03:01 PM
I want the assignment group auto populate based on the choices selection. I have a custom choice field and once I select from the choice i want a particular assignment group to auto populate. I need it to populate before I submit the form.
example: My choice field name is "Help" with choices of 'email, alert, Phone'. If I chose email, I want the assignment group to be IT, if I chose phone assignment group should be 'service desk' etc.
I have tried using assignment rule but the assignment group field is mandatory which prevent my assignment rule from working.
I have tried using this onchange client script but no luck. I am new to scripting.
if(choicevalue == 'IT'){
g_form.setValue('assignment_group','group_sys_id');
Thank you in advance.
Solved! Go to Solution.
- Labels:
-
Cost Management (ITSM)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2021 04:38 PM
That brings to mind the full onChange script has by default this bit at the beginning.
if (isLoading || newValue == '') {
return;
}
This stops the script from running if the newValue is blank. Sometimes you might want to remove the || newValue == '' part so that you can do something - like in this case if the choice is not mandatory, they could change it back to -- None -- which is stored as '', then you would want to clear the Assignment group. To build out the script, you would want various else if blocks followed by an else to cover the scenario of multiple choice changes.
if(newValue == 'IT'){
g_form.setValue('assignment_group','group_sys_id');
}
else if(newValue == 'Finance'){
g_form.setValue('assignment_group','finance_group_sys_id');
}
else if(newValue == 'HR'){
g_form.setValue('assignment_group','hr_group_sys_id');
}
else{
g_form.clearValue('assignment_group');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2021 03:11 PM
Hi Ken,
To hard-code the group sys_id for each choice, you have the right id on the setValue, but as written your if statement will never be true as choicevalue is undefined, so use something like this
if(g_form.getValue('choice_field_name' == 'IT'){
g_form.setValue('assignment_group','group_sys_id');
}
or even easier if this script is running onChange of the choice field
if(newValue == 'IT'){
g_form.setValue('assignment_group','group_sys_id');
}
Make sure to use the Value of the choice (case-sensitive), not the Label - which can be different.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2021 04:16 PM
Thanks Brad for your quick response. I used the second code and work for IT but if I change the choice the assignment group is still the same. I want the Assignment group to be empty if I did not select from the list.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2021 04:38 PM
That brings to mind the full onChange script has by default this bit at the beginning.
if (isLoading || newValue == '') {
return;
}
This stops the script from running if the newValue is blank. Sometimes you might want to remove the || newValue == '' part so that you can do something - like in this case if the choice is not mandatory, they could change it back to -- None -- which is stored as '', then you would want to clear the Assignment group. To build out the script, you would want various else if blocks followed by an else to cover the scenario of multiple choice changes.
if(newValue == 'IT'){
g_form.setValue('assignment_group','group_sys_id');
}
else if(newValue == 'Finance'){
g_form.setValue('assignment_group','finance_group_sys_id');
}
else if(newValue == 'HR'){
g_form.setValue('assignment_group','hr_group_sys_id');
}
else{
g_form.clearValue('assignment_group');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2021 05:11 PM
Thanks a lot Brad.