Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Business rule for assignment

simonaivanova
Kilo Contributor

Hello,

I need to create   business rule for direct assignment of a ticket. But I need to take the company property and to assign it to the group,

which is related to the concrete company.

For example: if the ticket comes from Company Naxex, it should be assigned to group SN_LDS. How I can write it in a script?

1 ACCEPTED SOLUTION

Here you go. Create a BEFORE business rule and modify the script as per your need.


(function executeRule(current, previous /*null when async*/) {



  // Add your code here


  var gr = new GlideRecord('sys_user');


  gr.addQuery('sys_id', current.caller_id);


  gr.query();


  if(gr.next())


  {


  var usrComp = gr.company;


  var gr1 = new GlideRecord('core_company');


  gr1.addQuery('sys_id', usrComp);


  gr1.query();


  if(gr1.next())


  {


  current.assignment_group = gr1.<FIELD COLUMN NAME OF GROUP';'


  }


  }



})(current, previous);



View solution in original post

10 REPLIES 10

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Simona,



You can configure this via Assignment rules. More info here.


Defining Assignment Rules - ServiceNow Wiki



The other option is the Business Rules as you have mentioned (in case you want this to work insert/update operation). However no script is required and it can be configured via filter conditions "When to run" and action tab.


Screen Shot 2017-05-18 at 1.44.46 PM.png


More info here.


Business Rules - ServiceNow Wiki


Hi Pradeep,


unfortunately we have business rule for assignment of all of the tickets to a concrete group, which will overwrites the assignment rule. That's why I decided to write a new business rule.


Thanks SImona for the update. in this case you can adjust your script in the previous Business rule



Script will be



if(current.company.getDisplayValue() == 'PASS COMPANY NAME HERE')


{


current.setDispalyValue('assignment_group', 'PASS ASSIGNMENT GROUP NAME HERE');


}



Please make sure field column names are correct as per your table.


The thing is that the company is not a static field, but should be taken as the information from the active directory, related to the user ID.


Also based on the company, the related assignment group will be different.