- 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-30-2017 11:22 PM
Hi Chris,
In name filed its showing Chris Nevile, do you want to show only Chris in name filed?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2017 11:44 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2017 12:01 AM
Hi Chris,
I believe that in your GlideRecord you could use the method .autoSysFields(false); which is going to prevent from the sys_ fields from getting automatically updated. On this case you can then try to assign your desired user to the sys_updated_by field just like you will do with any of the other table fields.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2017 12:21 AM
Hi Chris,
Please try below code to update sys_updated_by field.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord('incident');
gr.addQuery('sys_id', current.getUniqueValue());
gr.autoSysFields(false);
gr.query();
if(gr.next())
{
current.sys_updated_by = current.caller_id.name;
}
})(current, previous);