Update a record without updating its system fields(like sys_updated_by, sys_updated_on)?

shadab3
Tera Contributor

How can we update a record without updating its system fields(like sys_updated_by, sys_updated_on)?

1 ACCEPTED SOLUTION

Mohit Yadav
Tera Expert

Use

grObj.autoSysFields(false);

This will disable the update of sys_updated_on, sys_updated_by etc.

 

Please Mark Correct & Helpful, if Applicable. Thanks!

View solution in original post

4 REPLIES 4

Mohit Yadav
Tera Expert

Use

grObj.autoSysFields(false);

This will disable the update of sys_updated_on, sys_updated_by etc.

 

Please Mark Correct & Helpful, if Applicable. Thanks!

Allen Andreas
Administrator
Administrator

Hi,

You can go to background script: System Definition > Scripts - Background and conduct a gliderecord query, for example, find the record, update whatever fields is necessary and then use autoSysFields.

For example:

var gr = new GlideRecord('incident');
gr.addQuery('number', 'INC0012345');
gr.query();
if(gr.next()){
   gr.category = 'hardware';
   gr.autoSysFields(false);
   gr.update();
}

This would find the incident INC001235, set the category as hardware, and then update the record.

The line: gr.autoSysFields(false); prevents those system type fields from updating like sys_updated_on and sys_updated_by.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Tejas Tamboli
Giga Guru

Hello Shadab,

 

Yes, you can do it by using a function autoSysFields() in your server-side scripting.

Whenever you are updating a record set the autoSysFields() to false.

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

You can use below script:


var gr = new GlideRecord('incident');
gr.addQuery('number', 'INC10010');
gr.query();
if(gr.next())
{
    gr.autoSysFields(false);
    gr.short_description = 'ServiceNow';
    gr.update();
}

 

 

I hope this will help you.

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response useful to you and help others to find information faster.

Thanks,
Tejas