How to change display name for 'updated by'

Celliven
Giga Expert

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'.

find_real_file.png

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

1 ACCEPTED SOLUTION

Shiva Thomas
Kilo Sage

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'


Capture d



Here is the result...



Capture d



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.


View solution in original post

17 REPLIES 17

Hmmm... ðŸ¤”

Please execute your code under  "System Definition > Scripts - Background" and paste the error message here.

It's working! It's working! (insert anakin gif here). Thanks a ton. I made some minor changes and it looks like it works. I was running it in fix scripts first but your suggestion fixed it. Thanks!

You're most welcome! I'm glad I was able to help you. ðŸ˜‹