CI Relationship creation through transform map or Automatically
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2018 10:33 AM
Hi Team,
I have 2 ci classes, instead of creation manual entries in cmdb_rel_ci table. i just wanted to build the relation ship automatically while inserting the records.
for example: let us say
parent: parent class
few records are there in this class
child: child class
only two records are there in this class
i am inserting the records in parent, after insertion the relationship needs to be create automatically. there is common value for parent and child is ip address. if it is matched then attach this parent to the respective child.
parent Runs on::Runs Child like this.
i have the below script but i failed in usag
please give the information if you have anyyyy......
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2018 10:20 PM
Use transform map scripts to create relationships. I would suggest to use onComplete transform script for this. Use glideRecord to create relationships.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2018 10:24 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2018 10:52 PM
https://docs.servicenow.com/bundle/jakarta-platform-administration/page/script/server-scripting/concept/c_TransformMapScripts.html

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2020 04:30 PM
I had a similar use case and I tried an On After Transform Script to create the relationship record in cmdb_rel_ci table.
Below is the sample you can try:
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
//Create relationship
var app = new GlideRecord('cmdb_ci');
if (app.get('Field abc', source.reference field)) {
var rel = new GlideRecord('cmdb_rel_ci');
rel.addQuery('child', target.sys_id);
rel.addQuery('type', 'sys_id value');
rel.addQuery('parent', app.sys_id);
rel.query();
if (!rel.hasNext()) {
rel = new GlideRecord('cmdb_rel_ci');
rel.child = target.sys_id;
rel.type = 'sys_id value';
rel.parent = app.sys_id;
rel.insert();
}
}
})(source, map, log, target);