- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 2 weeks ago
Hello, Everyone.
If you need to update a massive number of records urgently or do something, you might consider using a background script. In this feature, unchecking the 'Cancel after 4 hours' checkbox removes the guardrail, allowing long-running operations.(If you really need to execute it.)
Once you understand its behavior, you can consider implementing it using other ServiceNow features as needed.
Here is an example of the script:
doingTooMany();
function doingTooMany(){
gs.log("START:Execute a too long running.");
var lgr = new GlideRecord("cmdb_ci");
lgr.addEncodeQuery('sys_class_name=cmdb_ci^EQ');
lgr.query();
gs.log("BEFORE:Execute a too long running.");
gs.log("COUNT:" + lgr.getRowCount());
while(lgr.next()){
var nowlgr = new GlideRecord("cmdb_ci");
if(nowlgr.get(lgr.getUniqueValue())){
// update something or script (use "nowlgr").
/* nowlgr.foobar = piyopiyo */
// if you need
nowlgr.setWorkflow(false);
nowlgr.autoSysFields(false);
nowlgr.update();
// consider system performance
gs.sleep(1000);
}
}
gs.log("END:Execute a too long running.");
}
Execution History Table
sys_script_execution_history.list
Terminate
v_transaction.list
Transaction(Search from All node)
v_cluster_transaction.list
in v_transaction, select record and use menus as below:
regards,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 2 weeks ago
Hi,Everyone.
From the perspectives of security and availability, we recommend implementing this using a Fix Script (or similar features).
For instance, with a Fix Script, you can explicitly select "Proceed in Background" via the button on the screen. The execution is then processed through the sys_trigger queue. Furthermore, logs generated within the script (e.g., gs.info) are automatically linked to the related list of that specific Fix Script record.
However, it is not possible to temporarily disable guardrails just for a one-time execution like the approach described in this post.
As mentioned in other posts, you should either narrow down the target batch size so that the script completes within 4 hours, or modify the timeout setting in the sysrule_quota record for the "Fix Script Processor", which can be extended up to a maximum of 30 days.
If you would also like to enable the rollback feature as with background scripts, please refer to the knowledge base article below.
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB1588181
Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
'Urgently' update a massive number of records, should not take over 4 hours. Update your script instead, or run it in batches. This is really terrible advice. You run the risk of blocking your instance entirely.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 2 weeks ago
Hi,Everyone.
From the perspectives of security and availability, we recommend implementing this using a Fix Script (or similar features).
For instance, with a Fix Script, you can explicitly select "Proceed in Background" via the button on the screen. The execution is then processed through the sys_trigger queue. Furthermore, logs generated within the script (e.g., gs.info) are automatically linked to the related list of that specific Fix Script record.
However, it is not possible to temporarily disable guardrails just for a one-time execution like the approach described in this post.
As mentioned in other posts, you should either narrow down the target batch size so that the script completes within 4 hours, or modify the timeout setting in the sysrule_quota record for the "Fix Script Processor", which can be extended up to a maximum of 30 days.
If you would also like to enable the rollback feature as with background scripts, please refer to the knowledge base article below.
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB1588181
Regards.