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

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);


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


Anil74
Tera Guru

Hi,



You can write the Business Rule,


Please see the below screenshot


BR.png


Hi Anil



i tried "javascript:gs.getuser().fullName;" but it returned "undefined"



find_real_file.png


I thought it may be name not full name, but that didn't work.



Chris


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.