How to update system field 'sys_updated_by' through script ?

Bhavesh Jain1
Giga Guru

Hi,

I would like to update the system field 'sys_updated_by' to a System user whenever any record gets updated in my table.

Background :

I have a catalog item 'Retire Asset'. When user raises the request, it goes for an approval. Once the approver approves the request, there is a Run script in the workflow which changes the asset state to Retired.

Now in the history I see that the Asset state was changed to 'Retired' by Approver. We want the history to show a System user and not approver name.

I have tried autoSysFields and setWorkflow already but you can suggest if it worked for you.

Please suggest.

Regards,

Bhavesh

3 REPLIES 3

Miriam Berg
Kilo Guru

Maybe you could put the script somewhere else, outside of the workflow? Like in a business rule?


Vivek Verma
Mega Sage
Mega Sage

‘autoSysFields’ is used to disable the update of ‘sys’ fields (Updated, Created, etc.) for a particular update. This really is only used in special situations. The primary example is when you need to perform a mass update of records to true up some of the data but want to retain the original update timestamps, etc.

 

//Change the category of all 'software' incidents to 'hardware' without updating sys fields
var gr = new GlideRecord('incident');
gr.addQuery('category', 'software');
gr.query();
while(gr.next()){
   gr.category = 'hardware';
   gr.autoSysFields(false);
   gr.update();
}
 
 
 
Thank You!
Please do mark as helpful Or correct answer.

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI Bhavesh,

 

What you have to do is impersonate into script first with admin user or with some system id. Because service now will always use the logged in user ID to update the field.


So i suggest you to impersonate in script first then check  it will work.


Thanks,
Ashutosh Munot