- 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
03-25-2025 01:54 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2017 03:55 AM
Hi Chirs,
Can you update the status of your requirement?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-03-2019 09:29 AM
I created this and it works great, but is there a way to make it apply to past created tickets? My business rule only applies to tickets created today forward. Anyway to change that?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2019 02:32 AM
Hi Brandon,
You need to create a Fix Script (or execute a Background Script)
var myCustomFieldName = 'u_updated_by'; // Name of your custom field
var tableToUpdate = 'incident'; // The table where you store your records
var gr = new GlideRecord(tableToUpdate);
gr.addNullQuery(myCustomFieldName); // No need to update the records that have been already processed by the Business Rule
gr.setLimit(10); // Try on a few records first, then increase the number. Useful to avoid timeout on large tables.
gr.query();
var userID = '';
while (gr.next()) {
grUser = new GlideRecord('sys_user');
grUser.get('user_name', gr.sys_updated_by); // Retrieve the user that last updated the record
gr.setValue (myCustomFieldName, grUser.getDisplayValue()); // Update the value of of your custom field with the full name of the user
gr.setWorkflow(false); // Do not run any other business rules.
gr.autoSysFields(false); // Do not update sys_updated_by, sys_updated_on, sys_mod_count, sys_created_by, and sys_created_on.
gr.update();
}
∴
Best regards from Switzerland
Shiva :¬,
If this reply assisted you, please consider marking it 👍Helpful.
This enables other customers to learn from this thread.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2019 07:06 AM
Awesome, thanks for the fast reply. I ran this script and it did not work, any idea what I am doing wrong? I looked at the table to confirm the name and I tried it with and without the ' before and after it. Thanks!
var myCustomFieldName = 'u_created_by_display_name'; // Name of your custom field
var tableToUpdate = 'sn_customerservice_case'; // The table where you store your records
var gr = new GlideRecord(tableToUpdate);
gr.addNullQuery('u_created_by_display_name'); // No need to update the records that have been already processed by the Business Rule
gr.setLimit(100); // Try on a few records first, then increase the number. Useful to avoid timeout on large tables.
gr.query();
var userID = '';
while (gr.next()) {
grUser = new GlideRecord('sys_user');
grUser.get('user_name', gr.sys_updated_by); // Retrieve the user that last updated the record
gr.setValue ('u_created_by_display_name', grUser.getDisplayValue()); // Update the value of of your custom field with the full name of the user
gr.setWorkflow(false); // Do not run any other business rules.
gr.autoSysFields(false); // Do not update sys_updated_by, sys_updated_on, sys_mod_count, sys_created_by, and sys_created_on.
gr.update();
}