Assignment Rule Script Not Working

Randy33
Tera Guru

I'm not sure why my scripts in the assignment rule are not working.

Randy33_0-1695559789638.png

The above script is not assigning Hardware to the Category field on the incident.  Any idea why?

 

 

3 REPLIES 3

RAMANA MURTHY G
Mega Sage

Hello @Randy33 ,

Assignment rules in ServiceNow are used to automatically assign tasks to users or groups based on pre-defined conditions.  Assignment Rules cannot assign values to the other fields, rather than Assignment Group and Assigned to fields.

 

You can write the script as 

 

if(current.category == 'Hardware')
   current.assignment_group.setDisplayValue('Hardware');

 

or you can write  as

 

if(current.category == 'Hardware')
   current.assignment_group = 'sys_id_of_group';    // replace sys_id of the group

 

 it will work...

 

Please mark my answer as helpful and correct, if it helps you

Thank you

 

 

Please mark my answer helpful  & correct if it helps you
Thank you

G Ramana Murthy
ServiceNow Developer

Sagar Pagar
Tera Patron

Hi @Randy33m

 

You can try this updated scripts as:

if (current.category == "Hardware"){
current.assignment_group.setDisplayValue("Hardware");
}

 

I would suggests you should use the condition builder with conditions instead of scripts.

Screenshot 2023-09-24 at 8.51.51 PM.png

 

Screenshot 2023-09-24 at 8.52.08 PM.png

 

 

If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers! 👍🏻
Thanks,
Sagar Pagar

The world works with ServiceNow

Check this

 

if (current.getDisplayValue('category') == "Hardware") {
  current.assignment_group.setDisplayValue('Hardware');
}
else if (current.getDisplayValue('category')== "Software") {
  current.assignment_group.setDisplayValue('Software');

else {
  current.assignment_group.setDisplayValue('Database');
}