How to auto populate assignment group based on a custom choices field

Ken61
Giga Guru

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.

1 ACCEPTED SOLUTION

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');
}

  

View solution in original post

5 REPLIES 5

Brad Bowman
Kilo Patron
Kilo Patron

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.

Ken61
Giga Guru

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.

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');
}

  

Ken61
Giga Guru

Thanks a lot Brad.