- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
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);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Use:
gr.autoSysFields(false);
gr.setWorkflow(false); // additional to ensures no business rules, flows, or scripts are triggered
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
**"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]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Use:
gr.autoSysFields(false);
gr.setWorkflow(false); // additional to ensures no business rules, flows, or scripts are triggered
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
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.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
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