Query on Business rule wrt Assignemnt group and Assigned to fields?

Suggy
Giga Sage

In my business rule, i have written like this

 

current.assigned_to =  "UserA"; -----> THIS WORKS

current.assignment_group = "GroupA"; ------> This DOES not work... WHY? (if I pass the sys_id, only then it works).

 

Why? both are reference fields. Then why the difference?

7 REPLIES 7

Brad Bowman
Kilo Patron
Kilo Patron

Assigned_to is referencing the sys_user table, so its value must be a sys_id on the sys_user table.  If "UserA" really means something like current.manager - another field that also references the sys_user table, then the value is a user sys_id so it works.  I wouldn't expect "Abel Tuter" to work in place of "UserA".  "GroupA" sounds like a field that references the sys_user_group table, so you would be trying to assign a sys_id from that table to the sys_user table which will never match since sys_ids are unique.

Amit Gujarathi
Giga Sage
Giga Sage

HI @Suggy ,
I trust you are doing great.

  1. Assigned To Field: The assigned_to field on most tables in ServiceNow, like the Incident table, is a reference to the sys_user table. When you set current.assigned_to = "UserA";, ServiceNow is smart enough to look up the sys_user table for a user with the name "UserA" and then set the assigned_to field to the sys_id of that user. This is a convenience feature provided by ServiceNow for user reference fields.

  2. Group Field: When you try to set a group using current.assigned_to = "GroupA";, it doesn't work because the assigned_to field is not referencing the sys_user_group table directly. Instead, it's referencing the sys_user table, and there's no user named "GroupA" in that table. To assign a group, you would typically use the assignment_group field, which is a reference to the sys_user_group table. Even then, directly assigning by name might not work, and using the sys_id is the most reliable method.

  3. Why sys_id works: The sys_id is a unique identifier for records in ServiceNow. When you provide the sys_id, ServiceNow doesn't have to guess or look up what you're referring to; it knows exactly which record you're pointing at. This is why setting reference fields using sys_id is more reliable and is considered a best practice.

In summary, while both fields are reference fields, they reference different tables. The convenience of assigning by name is primarily available for user fields, but it's always best to use sys_id for accuracy and reliability.


Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



Suggy
Giga Sage

Can anyone answer 🙂

Both assigned_to and assignment_group are reference fields, but they might be referencing different tables. For example, assigned_to typically references the sys_user table, while assignment_group references the sys_user_group table. If you're trying to set assignment_group to a value that doesn't exist in the sys_user_group table, it won't work.