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

Anil74
Tera Guru

Hi Chris,


In name filed its showing Chris Nevile, do you want to show only Chris in name filed?


Hi Anil



I want it to display Chris Neville, not d811474, which is the default display



find_real_file.png



Thanks



Chris


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.


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