Skip to page contentSkip to chat
ServiceNow support
    • Community
      Ask questions, give advice, and connect with fellow ServiceNow professionals.
      Developer
      Build, test, and deploy applications
      Documentation
      Find detailed information about ServiceNow products, apps, features, and releases.
      Impact
      Accelerate ROI and amplify your expertise.
      Learning
      Build skills with instructor-led and online training.
      Partner
      Grow your business with promotions, news, and marketing tools
      ServiceNow
      Learn about ServiceNow products & solutions.
      Store
      Download certified apps and integrations that complement ServiceNow.
      Support
      Manage your instances, access self-help, and get technical support.
Service Mapping NullPointerException error - Support and Troubleshooting
  • >
  • Knowledge Base
  • >
  • Support and Troubleshooting (Knowledge Base)
  • >
  • Service Mapping NullPointerException error
KB0678977

Service Mapping NullPointerException error


5531 Views Last updated : Aug 24, 2022 public Copy Permalink
KB Summary by Now Assist

Issue

Issue


When starting a discovery of a service map, discovery stops immediately and the java.lang.NullPointerException error can be seen in the log.

    NullPointerException

 

Troubleshooting


The NullPointerException error is thrown during recomputation of the business service. The most common reason for this error during recomputation is an existing duplicate dependencies in cmdb_rel_ci table. Having an NPE (NullPointerException) in such cases is not desirable; however, the recomputation logic behavior was completely updated in Kingston and such errors are not likely to happen in Kingston and newer releases.

To find the root cause for the issue you need to (short term):

  1. Find the CI that the recomputation was processing when the error happened
  2. Look for duplicate relationships for the device and remove them

For a long-term solution, you need to determine what caused the duplicate relationships.

Finding the CI

To find the CI, navigate to System Definition > Scripts - Background and run the following script. The output will be logged to the screen.

Note – Replace empty in gr.get('empty') with the sys_id for the business service.

gs.setProperty("glide.cmdb.logger.source.service_mapping.coordinator","info,warn,error,*"); 
gs.setProperty("glide.cmdb.logger.source.service_mapping.template", "info,warn,error,*"); 
gs.setProperty("glide.cmdb.logger.source.service_mapping.matching", "info,warn,error,*"); 
gs.setProperty('glide.transaction.max_logs', 200*10000); 

var gr = new GlideRecord('cmdb_ci_service_discovered'); 
gr.get('empty'); // <This line must be updated with service sys_id
var layerId= gr.layer; 
var layerGr= new GlideRecord('svc_layer'); 
layerGr.get(layerId); 
var env= sn_svcmod.ServiceContainerFactory.loadEnvironment(layerGr.environment); 

var allLayers= env.layers(); 
for (var i= 0 ; i< allLayers.length; i++) { 
var layer = allLayers[i]; 
layer.markRecomputationNeeded(); 
} 

SNC.ServiceMappingFactory.recomputeLayer(layerGr); 
gs.setProperty('glide.transaction.max_logs', 200*1000); 
gs.setProperty("glide.cmdb.logger.source.service_mapping.coordinator","info,warn,error"); 
gs.setProperty("glide.cmdb.logger.source.service_mapping.template", "info,warn,error"); 
gs.setProperty("glide.cmdb.logger.source.service_mapping.matching", "info,warn,error"); 

The CI with the duplicate relationship should be the last CI seen in the output before the NPE error.  In the following example output snippet, the CI would be 567bcdb49179390020e5db5405e32514.

service_mapping.template :>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>## UPDATE: convertRecordIntoElements: (CI:cmdb_ci_win_server:9667 # 567bcdb49179390020e5db5405e32514) => (cmdb_ci_win_server:9668) 
service_mapping.coordinator : Attempting to process layer Template on environment bb5e3069dbbb4304fc1cf9961d9619bb resulted in an exception:: no thrown error 
service_mapping.coordinator : >> java.lang.NullPointerException: no thrown error 
service_mapping.coordinator : : no thrown error

In this example, it was found that the CI had multiple "hosted on:hosts" relationship records to the same CI. For different CI records, there will be different relationship types that might cause the error. Once the CI is found, relationships in the cmdb_rel_ci table can be filtered for "parent = CI or child = CI", CI found in script output, to look for duplicate relationships. 

Identification rules

Very often such duplicate relationship/CI(s) are created due to identification rules that should be dependent but are set to independent. To look for such identification rules, navigate to System Definition > Scripts - Background and run the following script to find identifiers that are set to independent and should not be.

var gr = new GlideRecord('cmdb_identifier'); 
gr.addQuery('independent', 1); 
gr.query(); 
while (gr.next()) { 
if (GlideDBObjectManager.get().isInstanceOf(gr.applies_to, 'cmdb_ci_appl') || 
GlideDBObjectManager.get().isInstanceOf(gr.applies_to, 'cmdb_ci_lb_service')) { 
gs.print("Application " + gr.applies_to + " has an independent identifier rule"); 
} 
} 

Once these steps are followed (duplicate relationships are found and removed), the business service map discovery can be run again without the NPE error.

Background scripts, to search for duplicate application and cluster relationships

// find an application that runs on more than one host (wrong identifier). 
var gr = new GlideAggregate('cmdb_rel_ci');
gr.addQuery('type', '60bc4e22c0a8010e01f074cbe6bd73c3'); // runs on relation
gr.addQuery('child.sys_class_name','INSTANCEOF','cmdb_ci_server' );
gr.addQuery('parent.sys_class_name','INSTANCEOF','cmdb_ci_appl' );
gr.addAggregate('COUNT'); gr.groupBy('parent'); gr.query();
gs.print('*** Affected Applicataions: ***');
while (gr.next()) {        
if (gr.getAggregate('COUNT') > 1) {        
gs.print(gr.parent + ":" + gr.parent.name);    
}
}  

// find servers that are hosted on more then one cluster node 
var gr = new GlideAggregate('cmdb_rel_ci');
gr.addQuery('type', '5f985e0ec0a8010e00a9714f2a172815');
gr.addQuery('child.sys_class_name', 'cmdb_ci_win_server');
gr.addQuery('parent.sys_class_name', 'cmdb_ci_win_cluster_node');
gr.addAggregate('COUNT');
gr.groupBy('child');
gr.query();
gs.print('*** Affected Servers: ***');
while (gr.next()) {    
if (gr.getAggregate('COUNT') > 1) {        
gs.print(gr.child + ":" + gr.child.name);    
}
}

The world works with ServiceNow.

Sign in for more! There's more content available only to authenticated users Sign in for more!
Did this KB article help you?
Did this KB article help you?

How would you rate your Now Support digital experience?

*

Very unsatisfied

Unsatisfied

Neutral

Satisfied

Very satisfied

Very unsatisfied

Unsatisfied

Neutral

Satisfied

Very satisfied

What can we improve? Please select all that apply.

What are we doing well? Please select all that apply.

Tell us more

*

Do you expect a response from this feedback?

  • Terms and conditions
  • Privacy statement
  • GDPR
  • Cookie policy
  • © 2025 ServiceNow. All rights reserved.