The CreatorCon Call for Content is officially open! Get started here.

Assignment Rule Script not working

rashmianish
Kilo Expert

I have a HR Case being created using a Record Producer. This record producer has a field 'type_of_event', variable type is 'look up select box'. I'm trying to configure an assignment rule which should look at this field value and if the value is 'Event 1', the case should be assigned to Group 1. 

I have written the below script, but the assignment group is not being set.

var event=current.variables.type_of_event;   //tried with type_of_event.toString() too, not working.
if (event == 'sys_id of the event')     //tried giving name of the event too, not working.
{
current.assignment_group.setDisplayValue = 'Group 1';   //tried without setDisplayValue too
}

1 ACCEPTED SOLUTION

rashmianish
Kilo Expert

I found the answer to my question. Firstly thank you Pradeep for trying to help me, much appreciated 🙂

After providing the basic conditions on conditions tab of the Assignment rule (to make sure it won't execute on all), gave the below script in the script section. Worked like a champ.

var quest = new GlideRecord('question_answer');
quest.addQuery('table_sys_id',current.sys_id);
quest.addQuery('question','sys_id of the question you are querying');
quest.query();
while(quest.next())
{
if(quest.value =='sys_id of the value it should query') // A1 certificate of coverage
{
current.assignment_group ='sys_id of the assignment group the request should be assigned';
}
else
{
current.assignment_group='sys_id of the assignment group if condition fails; 
}
}

View solution in original post

6 REPLIES 6

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Rashmi,

Below is the updated script.

var event=producer.variables.type_of_event;   //tried with type_of_event.toString() too, not working.
if (event == 'sys_id of the event')     //tried giving name of the event too, not working.
{
current.assignment_group = 'PASS SYSID OF GROUP 1';   //tried without setDisplayValue too
}

Thanks for the quick reply Pradeep, have tried executing the above script; however the issue is it is not entering if loop at all. Just after Variable declaration I have given a log and there is no entry in the log table at all. Not sure if the variable type has any influence. 

Hi Rashmi,

Thanks for the update. Please replace var event=producer.variables.type_of_event; with var event=producer.type_of_event;

Sorry Pradeep that didn't work neither. Good news is now the log table entry has changed from no entry to 'undefined'.