How to update system field 'sys_updated_by' through script ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2015 05:04 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2015 06:01 AM
Maybe you could put the script somewhere else, outside of the workflow? Like in a business rule?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2018 11:26 PM
‘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.
var gr = new GlideRecord('incident');
gr.addQuery('category', 'software');
gr.query();
while(gr.next()){
gr.category = 'hardware';
gr.autoSysFields(false);
gr.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2018 11:37 PM
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