Evaluator.evaluateString() problem: java.lang.NullPointerException: error in servicenow
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2022 09:32 AM
Hi all,
I have few customize fields on Discovered Items table. I am trying to update the custom fields. I have to first try to get value from CMDB, if the value is not in cmdb, I have to get it from "initial source data" field from Discovered Items where the values are in the form of jason.
The script has to update 196k records, but it stops in the midway and gives the below error:
"Evaluator.evaluateString() problem: java.lang.NullPointerException: "
Need help to avoid this error. Here is the script:
var gr = new GlideRecord('sn_sec_cmn_src_ci');
gr.addEncodedQuery('cmdb_ciISNOTEMPTY');
gr.setLimit(5000);
gr.query();
while (gr.next()) {
//Get values for hostname, IP address, mac address from CMDB
gr.u_hostname = gr.cmdb_ci.host_name;
gr.u_ip_address = gr.cmdb_ci.ip_address;
gr.u_mac_address = gr.cmdb_ci.mac_address;
//Get hostname from cmdb ci for servers: name-first part
var classs = gr.cmdb_ci.sys_class_name;
if (classs == "cmdb_ci_win_server" || classs == "cmdb_ci_linux_server" || classs == "cmdb_ci_hpux_server" || classs == "cmdb_ci_unix_server" || classs == "cmdb_ci_esx_server" || classs == "cmdb_ci_server") {
var host1 = gr.cmdb_ci.name.split('.')[0];
gr.u_hostname = host1;
}
//parse source data
var obj = JSON.parse(gr.initial_source_data);
if(obj!=null){
//if ip is empty, get it from ipv4 - tenable
if (gr.u_ip_address == ''||gr.u_ip_address==null) {
var ipv4s = obj.ipv4s.replace(/[^a-zA-Z0-9,.-]/g, '');
gr.u_ip_address = ipv4s;
}
if (gr.u_ip_address == ''||gr.u_ip_address==null) {
var ipv4 = obj.ipv4.replace(/[^a-zA-Z0-9,.-]/g, '');
gr.u_ip_address = ipv4;
}
//if os is empty, get it from os - tenable
if (gr.os == '' || gr.os == "undefined"||gr.os == null) {
var base_os = obj.operating_systems;
var os1 = base_os.replace('["', '');
var os = os1.replace('"]', '');
gr.os = os;
}
//if fqdn is empty, get it from fqdn - tenable
var fqdn1 = obj.fqdn;
var fqdns = fqdn1.replace(/[^a-zA-Z0-9,.-]/g, '');
gr.u_fqdn = fqdns;
if (gr.u_fqdn != ''||gr.u_fqdn==null) {
//if host name is empty, get it from fqdn[first part] - tenable
if (gr.u_hostname == ''||gr.u_hostname==null) {
var host = gr.u_fqdn.split('.')[0];
gr.u_hostname = host;
}
}
//if host name is empty, get it from hostname - tenable
if (gr.u_hostname == ''||gr.u_hostname==null) {
var hostnames = obj.hostname.replace(/[^a-zA-Z0-9,.-]/g, '');
gr.u_hostname = hostnames;
}
//if host name is empty, get it from ip address- tenable
if (gr.u_hostname == ''||gr.u_hostname==null) {
gr.u_hostname = gr.u_ip_address;
}
//if mac address is empty get mac address from source data
if (gr.u_mac_address == ''||gr.u_mac_address==null) {
var mac = obj.mac_address;
gr.u_mac_address = mac;
}
//if last seen is empty get last seen from source data
var last_seen = obj.last_seen.substring(0, 10);
gr.u_last_seen = last_seen;
if (gr.u_last_seen == ''||gr.u_last_seen==null) {
gr.u_last_seen = gr.last_scan_date;
}
}
gr.update();
}
1 REPLY 1

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2022 10:00 AM
Hi,
Please check these links.
Mark Correct or Helpful if it helps.
Thanks,
Yousaf
***Mark Correct or Helpful if it helps.***