The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Varsha Srinivas
ServiceNow Employee
ServiceNow Employee

 Issue: Orphan "Contains::Contained by"relationship records between ESX Resource Pools are created in the cmdb_rel_ci table i.e., the parent/child is empty.

Root Cause: While creating the relationships, JSONCi script include sometimes passes the empty sys_id  for parent/child in the below code.

 

// Create new rels

for (name in desiredRelMap) {
   if (currentGen == 'parent')
      g_disco_functions.createRelationshipIfNotExists(obj.sys_id, name, currentRelType);
   else
      g_disco_functions.createRelationshipIfNotExists(name, obj.sys_id, currentRelType);
}



Fix: Before creating a relationship record, sys_id of the parent/child has to be validated if it empty. The fix is done in the DiscoveryFunctions Script include validating the sys_id. The issue is fixed in Quebec and Paris Patch 8 versions. In order to fix the issue in the previous versions, make the below changes in the DiscoveryFunctions script include. 

createRelationshipFromSysIds: function(parentId, childId, pDescription, cDescription) {
        if (JSUtil.nil(parentId) || JSUtil.nil(childId))
            return;
        if (!this.validCISysId(parentId) || !this.validCISysId(childId)) {
			return;
		}
        if (!cDescription && pDescription.indexOf("::") > -1) {
            var parts = pDescription.split("::");
            pDescription = parts[0];
            cDescription = parts[1];
        }
		var ECMDBUtil = SncECMDBUtil;
        return ECMDBUtil.createCIRelationship('cmdb_rel_ci', parentId, childId, pDescription, cDescription);
    },
    // Validate sysid
	validCISysId: function(sysID) {
		// Case 1: Check for null sys id
		if (gs.nil(sysID)) {
			gs.log('Invalid Rel CI Record :: Null SysID');
			return false;
		}
		//extracting only alphanumeric and comparing 32 chars
		if (sysID.match(/[0-9a-f]{32}/) == sysID) {
			return true;
		} else {
			// Case 3:SysID is not null
			// but it is not a valid sysID by its strig format [Alphanumeric and exactly 32 chars]
			gs.log('Invalid Rel CI Record :: Invalid SysID(Regex only) :SysID ' + sysID);
			return false;
		}
	},
Version history
Last update:
‎04-14-2021 01:41 AM
Updated by: