- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2025 06:39 AM
Hey All,
I'm having issues with my business rule. I'm doing service mapping requirement in which a parent ci needs the correct child cis to be mapped to it.
Currently, I have a business rule that in onBefore that calls my script include and my function. I need it to prevent duplicates for adding on the table.
business rule
onBefore() on insert and update table cmdb_rel_ci
code for script include
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
new getIPAddressesForCMDB.relationshipExists(current.parent, current.child);
gs.addErrorMessage("This is a duplicate found." + current.parent.getDisplayValue() + " " + current.child.getDisplayValue());
current.setAbortAction(true);
})(current, previous);
My script include with the function...only posting the functions that are important.
function relationshipExists(parentSysID, childSysID) {
var relGR = new GlideRecord('cmdb_rel_ci');
relGR.addQuery('parent', parentSysID);
relGR.addQuery('child', childSysID);
relGR.addQuery('type', getConsumesRelType());
relGR.query();
return relGR.hasNext();
}
function getConsumesRelType() {
var typeGR = new GlideRecord('cmdb_rel_type');
typeGR.addQuery('parent_descriptor', 'Contains');
typeGR.addQuery('child_descriptor', 'Contained by');
typeGR.query();
if (typeGR.next()) {
return typeGR.sys_id;
} else {
gs.warn('Contains::Contained by relationship type not found');
return null;
}
}
},
type: 'getIPAddressesForCMDB'
};
What am I doing wrong? When I try to insert a record on that cmdb_rel_ci it still inserts. By business rule should prevent this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2025 07:01 AM
After updating the script include as shared
Yes, also as shared by @palanikumar
Update BR script by adding parenthesis
new getIPAddressesForCMDB().relationshipExists(current.parent, current.child);
Regards
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2025 06:51 AM - edited 06-05-2025 06:52 AM
var getIPAddressesForCMDB = Class.create();
getIPAddressesForCMDB.prototype = {
initialize: function() {
},
relationshipExists: function(parentSysID, childSysID) {
var relGR = new GlideRecord('cmdb_rel_ci');
relGR.addQuery('parent', parentSysID);
relGR.addQuery('child', childSysID);
relGR.addQuery('type', this.getConsumesRelType());
relGR.query();
return relGR.hasNext();
},
getConsumesRelType: function() {
var typeGR = new GlideRecord('cmdb_rel_type');
typeGR.addQuery('parent_descriptor', 'Contains');
typeGR.addQuery('child_descriptor', 'Contained by');
typeGR.query();
if (typeGR.next()) {
return typeGR.sys_id;
} else {
gs.warn('getIPAddressesForCMDB: Contains::Contained by relationship type not found');
return null;
}
}
};
Hi @0890KM
Convert your script include into this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2025 07:01 AM
After updating the script include as shared
Yes, also as shared by @palanikumar
Update BR script by adding parenthesis
new getIPAddressesForCMDB().relationshipExists(current.parent, current.child);
Regards
Chaitanya

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2025 06:54 AM - edited 06-05-2025 06:56 AM
There is a problem in your Business rule. Parentheses(bracets) missing for Class initialization
Use this updated Line:
new getIPAddressesForCMDB().relationshipExists(current.parent, current.child);
Palani