- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2017 01:41 PM
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?
Solved! Go to Solution.
- Labels:
-
Best Practices
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2017 02:23 PM
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);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2017 02:08 PM
I'm clear with the first part
You mentioned "Also based on the company, the related assignment group will be different" [PS] : Where is this info stored?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2017 02:15 PM
It is in the field "Company", taken from the active directory as information.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2017 02:23 PM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2017 01:49 PM
Hi Simona,
You may want to look into Assignment Lookup Rules for this:
http://wiki.servicenow.com/index.php?title=Defining_Assignment_Rules#gsc.tab=0
If this doesn't meet your needs, can you please give more detail as to what you are trying to accomplish?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-18-2017 01:52 PM
Hello,
want to take the information from which office is the user and to assign the ticket to the relevant support group for that office.