Blog:Execute a too long running Script in Background
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago - last edited 2 hours ago
Hello, Everyone.
If you need to update a massive number of records urgently, 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.)
Here is an example of the script:
updateTooMany();
function updateTooMany(){
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 update
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
select record and use menus as below:
regards,
0 REPLIES 0