Pass sys_id or Name for reference fields?

Suggy
Giga Sage

I have written Before Insert Business rule on Incident form.

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

     current.assignment_group = 'Analytics';
     current.assigned_to = 'Luke Wilson';
})(current, previous);

 

But once the incident is created, this is how it looks:

del2.png

As seen above, 'Assingned to' is set to the right value from business rule, but why not for 'Assignment group'?

- If i pass the sys_id for assignment group, then it works

- but for Assigned to field, if I pass sys_id/user name/user ID.... still it works.

 

What is the issue?

 

Note - Display value is set to FALSE for ALL the fields for both User and Group table.

10 REPLIES 10

Ryan_Gillespie
Kilo Guru
Kilo Guru

When setting the value for a reference field, the value itself is the sys_id. If you view the XML of a record with reference fields you will see the value shows the sys_id and then it will also show you the display value for that record. By passing the sys_id in your script, you will set the value for the field. You can see in the screenshot below the red rectangle highlights the field in the XML while the green highlights the actual value for the field.

RyanGillespie2_0-1670946945419.png

 

@Ryan_Gillespie  not sure if you got my question right.

 

My script is like this:

 

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

     current.assignment_group = 'Analytics';
     current.assigned_to = 'Luke Wilson';
})(current, previous);

 

Both Assigned to and Assignemnt group are REFERENCE fields.

 

I am passing the NAME for both the fields (NOT sys_id).

 

Finally, only the Assigned to is set and not Assignment group. Why...

 

In XML this is what i see:

Suggy_1-1670955463003.png

 

 

The system may be able to find the user but the answer is that you need to be passing in the sys_id, not the 'name'. It might also come down to table and field indexing.

Ok, I am looking for that answer then.. like for 'Assinged to' field, if I pass the User ID or user Name or Sys_ID, it works fine. but how ? why not same logic for other reference fields 🙂

I can tell you that for something like a transform map, it'll use a 'name' to try to find a match but beyond that, I'm not sure. I've not seen a successful script pass in a 'name' vs a sys_id. It's always had to be a sys_id. Now for something like a choice field, you would need to pass the value of the choice.