Help creating assignment rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2024 12:03 PM
On the incident form I have 3 reference fields. (Only for the first 2: the first being the parent of the second).
I need to define an assignment rule that when an incident is created, the assignment group will be automatically populated with:
- the group associated with the first field if the second and third fields are empty, the first is not empty and is the last filled in
- the group associated with the second field if the first 2 fields are not empty, the third field is empty, and the last filled field is field number 2
- the group associated with the third field if all are filled and the third is the last filled
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2024 01:37 PM - edited ‎04-16-2024 01:38 PM
Hi @B_pppppp,
No worries, thanks for that, makes sense.
Correct me if I am wrong, but these 3 fields must be populated in an order? i.e. field 2 can be populated only when field 1 is populated. Field 3 can be populated only when Field 1 & 2 are populated.
If the above assumption is valid, you can still use an Assignment Rule and this would be a better approach than using a Client Script. Client Script only applies on a UI (form view in this instance) and you may be creating an Incident across different UIs (e.g. portal, API).
So, with the Assignment Rule, I would prefer creating multiple rules with simple conditions, but if you want to consolidate them into one, you can use a script like below:
var firstField = current.getValue('first_field');
var secondField = current.getValue('second_field');
var thirdField = current.getValue('third_field');
if( !gs.nil(firstField ) && gs.nil(secondField) && gs.nil(thirdField)) //only the first field is populated
{
current.assignment_group = current.first_field.assignment_group_field.toString();
}
else if( !gs.nil(firstField ) && !gs.nil(secondField) && gs.nil(thirdField)) //only the last field is not populated
{
current.assignment_group = current.second_field.assignment_group_field.toString();
}
else if( !gs.nil(firstField ) && !gs.nil(secondField) && !gs.nil(thirdField)) //all fields are populated
{
current.assignment_group = current.third_field.assignment_group_field.toString();
}
If you insist on using a Client Script, you can apply the same logic as above with a few tweaks.
Cheers