Problem with a data source creating duplicate relationships
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2024 08:16 AM
We are having a problem with duplicate relationships we are trying to create in our CMDB from Data Sources. I found a post about using a transform script a while ago to make this work and I emulated it but I wonder if perhaps I have done so improperly?
The data should be using the child, parent, and type to coalesce.
The transform is set to run onAfter and those are:
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var sourceParentCIName = source.u_host;
var ciClass = 'cmdb_ci_endpoint_db2sql';
var gr = new GlideRecord(ciClass);
gr.addQuery('name', sourceParentCIName);
gr.query();
if (gr.next()) {
target.parent = gr.sys_id;
target.update();
}
})(source, map, log, target);
and
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var sourceChildCIName = source.u_host;
var ciClass = 'cmdb_ci_server';
var gr = new GlideRecord(ciClass);
gr.addQuery('name', sourceChildCIName);
gr.query();
if (gr.next()) {
target.child = gr.sys_id;
target.update();
}
})(source, map, log, target);
I was wondering if maybe it is making a new relationship because it's starting the process before it is matched to the correct CIs, then onAfter is matching it to the correct CI, and creating the relationship, even though one already exists for those? But when I try other options for When it doesn't seem to work.
Thank you if anyone can help point me in the right direction.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2024 01:09 PM
The CI relationships are stored in cmdb_rel_ci table.
You don't need onAfter transform scripts, instead use the same logic in your field map script.
for Parent Field Map :
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var sourceParentCIName = source.u_host;
var ciClass = 'cmdb_ci_endpoint_db2sql';
var gr = new GlideRecord(ciClass);
gr.addQuery('name', sourceParentCIName);
gr.query();
if (gr.next()) {
return gr.sys_id;
}
})(source, map, log, target);
For Child Field Map :
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
var sourceChildCIName = source.u_host;
var ciClass = 'cmdb_ci_server';
var gr = new GlideRecord(ciClass);
gr.addQuery('name', sourceChildCIName);
gr.query();
if (gr.next()) {
return gr.sys_id;
}
})(source, map, log, target);
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2024 07:21 PM
I would suggest Call IRE API