- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2017 11:17 PM
Hi
I want to update the display value of the field 'sys_updated_by' as it currently shows 'user_name' and I would rather it show 'name'.
I am not sure if I need to use a business rule or it is in the dictionary attributes of the field.
Any help appreciated.
Chris
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2017 01:12 AM
Hi Chris,
Just a warning... The field 'sys_updated_by' not a reference to the client table, and don't contain a sys_id. It's a simple string, probably for performance reason. But it's a very low level field for the platform. If you modify its behavior, you may suffer from unexpected side-effects later on.
I strongly recommend that you leave this field for the system, and create a new one for your own usage. In Anil screenshot you may notice he created a custom 'u_updated_by' field, I suggest you do something similar.
I created a field 'u_updater' on the Task table. Set it read-only. Created a business rules run on insert & updates to set the 'u_updater' field. I preferred to use a different name to avoid possible confusion.
The correct code snippet you want to use one of these:
javascript: gs.getUserDisplayName(); // Will return the display name 'Shiva Thomas'
javascript: gs.getUser().getLastName(); // Will return the last name 'Thomas'
Here is the result...
If you decide to use the user's last name, be aware of possible minor complications once you have several users sharing the same family name. This is why the platform uses 'user_name' instead, as it's a unique value with no possible duplicate.
The foolproof way is to use the full display name instead.
You could also use a reference string, pointing to the user table, and setting it with gs.getUserID(); but I'm not sure of the performance impact on your instance. I suppose there is a reason why ServiceNow did not implement 'sys_updated_by' it that way.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2017 12:24 AM
Please have same code with less number of lines.
(function executeRule(current, previous /*null when async*/) {
var gr = new GlideRecord('incident');
gr.get(current.getUniqueValue());
gr.autoSysFields(false);
current.sys_updated_by = current.caller_id.name;
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2017 12:40 AM
Hi Shishir
I am now finding the sys_updated_by record locked, even with an elevated role.
I'll try your suggestion once I sort out what has happened, as it was accessible earlier.
Thanks
Chris

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2017 11:53 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2017 12:44 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2017 01:12 AM
Hi Chris,
Just a warning... The field 'sys_updated_by' not a reference to the client table, and don't contain a sys_id. It's a simple string, probably for performance reason. But it's a very low level field for the platform. If you modify its behavior, you may suffer from unexpected side-effects later on.
I strongly recommend that you leave this field for the system, and create a new one for your own usage. In Anil screenshot you may notice he created a custom 'u_updated_by' field, I suggest you do something similar.
I created a field 'u_updater' on the Task table. Set it read-only. Created a business rules run on insert & updates to set the 'u_updater' field. I preferred to use a different name to avoid possible confusion.
The correct code snippet you want to use one of these:
javascript: gs.getUserDisplayName(); // Will return the display name 'Shiva Thomas'
javascript: gs.getUser().getLastName(); // Will return the last name 'Thomas'
Here is the result...
If you decide to use the user's last name, be aware of possible minor complications once you have several users sharing the same family name. This is why the platform uses 'user_name' instead, as it's a unique value with no possible duplicate.
The foolproof way is to use the full display name instead.
You could also use a reference string, pointing to the user table, and setting it with gs.getUserID(); but I'm not sure of the performance impact on your instance. I suppose there is a reason why ServiceNow did not implement 'sys_updated_by' it that way.