Scheduled job not picking up relevant records based on one small change to the filter.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi, I was recently assigned to change the fitler criteria of a scheduled job. The filter was basically to look into table 1 and pick all the records which start with lbg- and put them into another table if they had been updated in the last 2 days, the requirement was to change that to pick records which contains lbg. So literally just an operator change. When I first did the change in dev it worked, but when the change moved to test it stopped working, now its not working in dev either.
Here is the code below as it was when I didn't change it:
//Review all records updated from last week from Network Nodes table
var grXBBCNN = new GlideRecord('x_btesi_bt_cmdb_network_nodes');
grXBBCNN.addEncodedQuery("u_ntn_managed_flag=Y^sys_updated_onRELATIVEGT@dayofweek@ago@2");
//grXBBCNN.addEncodedQuery("ntn_man_host_nameSTARTSWITHLBG-");
//grXBBCNN.setLimit(22);
grXBBCNN.query();
while (grXBBCNN.next()) {
//Initialize BT Network Node table
var grUCCBNN = new GlideRecord('u_cmdb_ci_bt_network_node');
//Get BT Product Type and Model Number from Port Node Product table
var grXBBCPNPT = new GlideRecord('x_btesi_bt_cmdb_port_node_products');
grXBBCPNPT.get(grXBBCNN.getValue('ntn_ndp_id'));
var btProductType = grXBBCPNPT.getElement('ndp_ndt_id.ndt_name').getValue() || '';
var modelNumber = grXBBCPNPT.getValue('ndp_name') || '';
... rest of script which picks the fields and does things
I literally only changed the line
Script execution error: Script Identifier: null.null.script, Error Description: java.lang.NullPointerException: Cannot invoke "Object.toString()" because "value" is null, Script ES Level: 0
Couldn't decipher the stack trace resulting from the following JavaScriptException:
java.lang.NullPointerException: Cannot invoke "Object.toString()" because "value" is null: org.mozilla.javascript.JavaScriptException: java.lang.NullPointerException: Cannot invoke "Object.toString()" because "value" is null: org.mozilla.javascript.Context.makeJavaScriptException(Context.java:2631) org.mozilla.javascript.Context.throwAsScriptRuntimeEx(Context.java:2615) org.mozilla.javascript.MemberBox.invoke(MemberBox.java:243)
Can someone please tell me what's going on and why its not working at all anymore.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
CONTAINS won't work in encodedQuery
you need to use LIKE
var grXBBCNN = new GlideRecord('x_btesi_bt_cmdb_network_nodes');
grXBBCNN.addEncodedQuery("u_ntn_managed_flag=Y^ntn_man_host_nameLIKElbg^sys_updated_onRELATIVEGT@dayofweek@ago@2");
grXBBCNN.query();
while (grXBBCNN.next()) {
// Defensive checks before accessing fields
var ndpId = grXBBCNN.getValue('ntn_ndp_id');
if (ndpId) {
var grXBBCPNPT = new GlideRecord('x_btesi_bt_cmdb_port_node_products');
if (grXBBCPNPT.get(ndpId)) {
// safe to getElement or getValue
// ...
}
}
}
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
I mentioned that I already tried 1 encoded query with all the filters and just copy pasted it and it does use LIKE, but that is not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday - last edited yesterday
@snow_beginner If you are using encodedQuery it should be “LIKE” instead of “CONTAINS”
It will fetch every string containing your string in that column.
Please mark the answer correct/helpful accordingly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi @RaghavSh
var grXBBCNN = new GlideRecord('x_btesi_bt_cmdb_network_nodes');
grXBBCNN.addEncodedQuery("(u_ntn_managed_flag=Y^ntn_man_host_nameLIKElbg^sys_updated_onRELATIVEGT@dayofweek@ago@2");
// SFSTRY0038587: only bring in records starting LBG- (any case)
//grXBBCNN.addEncodedQuery("ntn_man_host_nameLIKEBG");
// end SFSTRY0038587
//grXBBCNN.setLimit(22);
grXBBCNN.query();
while (grXBBCNN.next()) {
This is what I have in there. I tried with just 1 encoded query like Ankur mentioned and it uses LIKE.
It's commented out now, but I also tried it like below
var grXBBCNN = new GlideRecord('x_btesi_bt_cmdb_network_nodes');
grXBBCNN.addEncodedQuery("(u_ntn_managed_flag=Y^sys_updated_onRELATIVEGT@dayofweek@ago@2");
// SFSTRY0038587: only bring in records starting LBG- (any case)
grXBBCNN.addEncodedQuery("ntn_man_host_nameLIKEBG");
// end SFSTRY0038587
Both are not picking up the relevant record that I made and updated today (an hour ago) or any of the other ones made/updated in the last few days.