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

SuhasPSalunkhe
Kilo Guru

Best practice -

Use sysId instead of name.

 

Why - there may be duplicate value for same text like in your case Assignment group name can be same for other group name.

There is only 1 group with that name.

Community Alums
Not applicable

Hi @Suggy ,

 

If you are updating a reference field, then you have to use the sys_id of the record. 

 

In your case, you are hardcoding the values to the assignment group and assigned to field. Which might work in some cases and not all the time. If you are updating the assignment group and assigned to dynamically, then you have to use the sys_id of the record.

 

Out of curiosity -  Did you refresh the record once the Assigned to field has been updated? Possible that it might be blank after refreshing. 

 

Regards,

Gagan k

Thanks for replying, but that does not answer my question.

After refreshing, its the same.