Script for RITM Assignment Rule

steveturley
Tera Guru

Hi, I'm trying to develop a script that will assign the RITM based upon the Requested For users location.

 

I've tried two scripts below based upon other community posts. Could anyone advise what's incorrect? I'm not even sure if my syntax is correct

 

steveturley_0-1672834849045.png

 

or

 

steveturley_1-1672834911555.png

 

Thanks!

 

 

 

6 REPLIES 6

Laszlo Balla
ServiceNow Employee
ServiceNow Employee

First of all, why are you trying to script this when you could just use the assignment rules module, data look-up rules, flow designer, business rules, etc.?
https://docs.servicenow.com/en-US/bundle/tokyo-platform-administration/page/administer/task-table/co...

Don't code if your don't have to.

 

If you insist on doing this with code, or just want to fix it, please explain where were you trying to do this? As the requester will most likely not change, there is no need to use client side scripts (as implied by your second screenshot), but rather server-side, e.g. a before insert business rule, which could indeed access the details of the RITM record via the 'current' object. When working with reference field values, such as the requested for (or its location even) or the assignment group, you will want to get and set values using the sys_id of the respective record (loation or group), something like:

var reqLocation = ''; // Sys_id of the location record from he 'cmn_loation' table, e.g.: 
'25b3d04b0a0a0bb300176b546c22db27'
var groupId = ''; // Sys_id of the assignment group from the 'sys_user_group' table

if(current.requested_for.loation == reqLocation) {
current.setValue('assignment_group', groupId);
}

 

 

 

Apologies, I should've probably explained better. This was as a script in an Assignment Rule. Assignment Rules are currently used to assign RITM's to Groups (SCTASKS aren't used atm) so I was trying to continue the precedent.

 

I know I could create several location-specific Assignment Rules per item, but I thought it'd be neater to create just one per item that would be able to assign to a specific group based upon the Requested For's location

Laszlo Balla
ServiceNow Employee
ServiceNow Employee

Again, I don't see the need to use scripts for this, unless there is some advanced logic needed to get some values.

 

In the Condition field of the 'Applies To' tab, simply choose 'Show Related Field' at the bottom of the choice list, and then just dot-walk to the user's location like this:

LaszloBalla_0-1672849718904.png

 

Then simply choose the desired group in the 'Assign To' tab.

 

The sole fact that it was scripted before doesn't mean that it should be like that 🙂 If you are in charge now, why not make it more user friendly for your future successor? 😄

If you are not comfortable changing the existing assignment rule, then just disable it, and create yours as a new one.

 

Would that approach mean I'd have to create an Assignment Rule per Item per Assignment Group?

 

The current rules aren't scripted, but they are currently 'Item X = Assignment Group Y' so quite basic

 

With my new requirement I was just trying to see if I could keep the Assignment Rules to one per item, but use some script to dynamically work out the Assignment Group by Requests For location

 

I'm all for not using script! - I avoid it wherever possible. I thought this could be quite simple though.

 

Thanks for your help.