Background script to update Change Requests producing nullpointerexception on gr.update
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2018 06:13 AM
I have a requirement to update all change requests with a worknote that includes a short note and also includes the name of the configuration item associated with the CR.
I've got a background script written that can successfully update CR's that have a configuration item with a note and the configuration item name.
I've discovered a large number of CR's that do not have configuration items entered into the CMDB_CI field. (A result of UI policies changing over time). Since I have CR's with no configuration item I need to add a different note to the worknotes of these CR's that advises no configuration item was ever selected.
Here is the script I'm running:
var gr = new GlideRecord('change_request');
var note = "This record did not have a Configuration Item attached.";
gr.addNullQuery('cmdb_ci');
gr.query();
while(gr.next()){
gr.work_notes = note;
gr.update();
}
When I run this script I get the following error:
JavaScript evaluation error on:
var gr = new GlideRecord('change_request');
var note = "This record has been modified as part of the CMDB clean-up project. This record did not have an attached Configuration Item at the time of CMDB clean-up.";
gr.addNullQuery('cmdb_ci');
gr.query();
while(gr.next()){
gr.work_notes = note;
gr.update();
}
Root cause of JavaScriptException: java.lang.NullPointerException
: java.lang.NullPointerException:
Any ideas on what is happening here?
- Labels:
-
Change Management

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2018 06:18 AM
Try this for the work note entry line:
gr.work_notes.setJournalEntry(note);
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2018 06:23 AM
Unfortunately this produces a similar error:
JavaScript evaluation error on:
var gr = new GlideRecord('change_request');
var note = "This record has been modified as part of the CMDB clean-up project. This record did not have an attached Configuration Item at the time of CMDB clean-up.";
gr.addNullQuery('cmdb_ci');
gr.query();
while(gr.next()){
gr.work_notes.setJournalEntry(note);
gr.update();
}
Root cause of JavaScriptException: java.lang.NullPointerException
: java.lang.NullPointerException:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2018 06:27 AM
Perhaps worth mentioning, when I run the opposite query I am successfully updating records without error:
var gr = new GlideRecord('change_request');
var note = "This record has been modified as part of the CMDB clean-up project. The original configuration item record related to this record is: ";
gr.addNotNullQuery('cmdb_ci');
gr.query();
if(gr.next()){
gr.work_notes = note + gr.cmdb_ci.getDisplayValue();
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2018 06:30 AM
Here is a copy of the complete error I receive when running the background script:
Time: 0:00:00.209 id: _1[glide.2] for: SELECT task0.`sys_id` FROM task task0 WHERE task0.`sys_class_name` IN ('change_request','change_request_imac') AND task0.`cmdb_ci` IS NULL /* , gs:AE29A3CD13BED7001F81B7A66144B050, tx:681c001513321b001f81b7a66144b0f6 */
ENGINE: Workflow CommandManager.killSwitch has 1 observers
completed Change moves to Scheduled(fcc67b0f13402e002a5db4828144b04f): event=update
ENGINE: Workflow CommandManager.killSwitch has 1 observers
completed Change moves to Scheduled(fcc67b0f13402e002a5db4828144b04f): event=update
ENGINE: Workflow CommandManager.killSwitch has 1 observers
completed Change moves to Scheduled(fcc67b0f13402e002a5db4828144b04f): event=update
ENGINE: Workflow CommandManager.killSwitch has 1 observers
completed Change moves to Scheduled(fcc67b0f13402e002a5db4828144b04f): event=update
ENGINE: Workflow CommandManager.killSwitch has 1 observers
completed Change moves to Scheduled(fcc67b0f13402e002a5db4828144b04f): event=update
ENGINE: Workflow CommandManager.killSwitch has 1 observers
completed Change moves to Authorize(396d4c791382cb00ff9276666144b010): event=update
ENGINE: Workflow CommandManager.killSwitch has 1 observers
completed Change moves to Authorize(396d4c791382cb00ff9276666144b010): event=update
ENGINE: Workflow CommandManager.killSwitch has 1 observers
completed Change moves to Scheduled(0ebdc4b91382cb00ff9276666144b0a7): event=update
ENGINE: Workflow CommandManager.killSwitch has 1 observers
completed Change moves to Authorize(396d4c791382cb00ff9276666144b010): event=update
*** Script: checking permissions for /connect/message/3e5acfbc13ace2402a5db4828144b044: true
ENGINE: Workflow CommandManager.killSwitch has 1 observers
completed Change moves to Scheduled(fcc67b0f13402e002a5db4828144b04f): event=update
ENGINE: Workflow CommandManager.killSwitch has 1 observers
completed Change moves to Authorize(396d4c791382cb00ff9276666144b010): event=update
*** Script: checking permissions for /connect/message/a0657a0b1338e640ef9df6d96144b018: true
ENGINE: Workflow CommandManager.killSwitch has 1 observers
completed Change moves to Scheduled(0ebdc4b91382cb00ff9276666144b0a7): event=update
ENGINE: Workflow CommandManager.killSwitch has 1 observers
completed Change moves to Authorize(396d4c791382cb00ff9276666144b010): event=update
Couldn't decipher the stack trace resulting from the following JavaScriptException:
java.lang.NullPointerException: org.mozilla.javascript.JavaScriptException: java.lang.NullPointerException: org.mozilla.javascript.Context.makeJavaScriptException(Context.java:1925)
org.mozilla.javascript.Context.throwAsScriptRuntimeEx(Context.java:1911)
org.mozilla.javascript.MemberBox.invoke(MemberBox.java:143)
org.mozilla.javascript.FunctionObject.doInvoke(FunctionObject.java:670)
org.mozilla.javascript.FunctionObject.call(FunctionObject.java:614)
org.mozilla.javascript.ScriptRuntime.doCall(ScriptRuntime.java:2582)
org.mozilla.javascript.optimizer.OptRuntime.callProp0(OptRuntime.java:85)
org.mozilla.javascript.gen.null_null_script_3347._c_script_0(null.null.script:7)
org.mozilla.javascript.gen.null_null_script_3347.call(null.null.script)
org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:563)
org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3421)
org.mozilla.javascript.gen.null_null_script_3347.call(null.null.script)
org.mozilla.javascript.gen.null_null_script_3347.exec(null.null.script)
com.glide.script.ScriptEvaluator.execute(ScriptEvaluator.java:263)
com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:110)
com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:76)
com.glide.script.fencing.GlideScopedEvaluator.evaluateScript(GlideScopedEvaluator.java:343)
com.glide.script.fencing.GlideScopedEvaluator.evaluateScript(GlideScopedEvaluator.java:263)
com.glide.script.fencing.GlideScopedEvaluator.evaluateScript(GlideScopedEvaluator.java:250)
com.glide.processors.ScriptProcessor.evaluateScript(ScriptProcessor.java:330)
com.glide.processors.ScriptProcessor.runScript(ScriptProcessor.java:219)
com.glide.processors.ScriptProcessor.process(ScriptProcessor.java:177)
com.glide.processors.AProcessor.runProcessor(AProcessor.java:474)
com.glide.processors.AProcessor.processTransaction(AProcessor.java:199)
com.glide.processors.ProcessorRegistry.process0(ProcessorRegistry.java:178)
com.glide.processors.ProcessorRegistry.process(ProcessorRegistry.java:167)
com.glide.ui.GlideServletTransaction.process(GlideServletTransaction.java:31)
com.glide.sys.Transaction.run(Transaction.java:2037)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
java.lang.Thread.run(Thread.java:748)
JavaScript evaluation error on:
var gr = new GlideRecord('change_request');
var note = "This record has been modified as part of the CMDB clean-up project. This record did not have an attached Configuration Item at the time of CMDB clean-up.";
gr.addNullQuery('cmdb_ci');
gr.query();
while(gr.next()){
gr.work_notes.setJournalEntry(note);
gr.update();
}
Root cause of JavaScriptException: java.lang.NullPointerException
: java.lang.NullPointerException: