The CreatorCon Call for Content is officially open! Get started here.

I want to update a incident category without increased count in updates field

ServiceNow Use6
Tera Guru

Hi,

I wrote this code, but updates increased. Kindly help.

 

var gr = new GlideRecord('incident');
gr.addQuery('number', 'INC0007001');
gr.query();
if(gr.next()){
	gr.category = 'network';
	gr.autoSysFields(true);
	gr.update();
}
gs.addInfoMessage('the total number of updates are ' + gr.sys_mod_count);
1 ACCEPTED SOLUTION

Rafael Batistot
Kilo Patron

Hi @ServiceNow Use6 

 


Use: 

 

gr.autoSysFields(false);

gr.setWorkflow(false); // additional to ensures no business rules, flows, or scripts are triggered

 

View solution in original post

5 REPLIES 5

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @ServiceNow Use6 

 

**"I’m not a developer, but I believe what you're referring to is more of a best practice rather than a recommended approach. As per the out-of-the-box (OOTB) behavior, whenever any record or field is changed, it captures the 'Updated By' and 'Updated' timestamp, as well as the 'Created By' and 'Created' timestamp based on the last change.

Could you please clarify why you don’t want to count incremental updates?

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Rafael Batistot
Kilo Patron

Hi @ServiceNow Use6 

 


Use: 

 

gr.autoSysFields(false);

gr.setWorkflow(false); // additional to ensures no business rules, flows, or scripts are triggered

 

Ankur Bawiskar
Tera Patron
Tera Patron

@ServiceNow Use6 

when you use setWorkflow(false) the update won't be audited and hence the Updates count won't increase

var gr = new GlideRecord('incident');
gr.addQuery('number', 'INC0007001');
gr.query();
if(gr.next()){
	gr.category = 'network';
	gr.autoSysFields(true);
        gr.setWorkflow(false);
	gr.update();
}
gs.addInfoMessage('the total number of updates are ' + gr.sys_mod_count);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

raviteja1600
Tera Guru

Hi @ServiceNow Use6 ,

 

You are not stoping the Business rules and other scripts running on the form. Due to that the audit count is increasing.

 

Use the belowscript

var gr = new GlideRecord('incident');
gr.addQuery('number', 'INC0007001');
gr.query();
if(gr.next()){
	gr.category = 'network';
	gr.autoSysFields(true);
    gr.setWorkflow(false); // which stops the running of other scripts on the form
	gr.update();
}
gs.addInfoMessage('the total number of updates are ' + gr.sys_mod_count);  

As per the ServiceNow recommendations, don't use the "gr" in the script.

 

If the provided solution is helpful, please mark it as helpful and accept the solution.

 

Regards,

Raviteja