- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2023 08:41 AM
Hi Developers,
I have a requirement, Where I need to add multiple services as child from (cmdb_ci_service_technical) table to Business Application(cmdb_ci_business_app) table.
It can be done manually but I will have 500-700 records.
Please suggest best & less complicated way to achieve this.
Thank you.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2023 02:14 AM
Hi @Naveen87
Why don't you create a import set and prepare an ecel and import at once in the Relationship CI table.
I think that will be the best possible way to achieve this. No scripting, no hassle.
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2023 08:51 AM
Hello,
You could run a background or fix script if all of your CIs are already created in the cmdb. Take the sys_id of the business application and loop through all the CIs that need to be a child and create a record in the cmdb_rel_ci table where parent = business app and child = ci record and type is whatever relationship type you're defining.
Thanks,
Joe S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2023 10:51 PM
Hi Joe,
Thank you for the response.
I'm not good at scripting.
Please help me with the script.
I tried this but I don't think it's correct.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2023 07:05 AM - edited 05-15-2023 07:17 AM
Hi Naveen,
Aman is correct you could do an import set and create the records in the relationship table that way. Since you're CI records already exist that would require exporting them out to a file and then importing into the rel_ci table.
If you want to go the script route, here is an example of how you could script this in a fix script.
var busApp = 'cc45f84e4732211004ed5882e36d4392'; //sys_id of your business application record
//you need to get all of your CI records that need to have a relationship to the business application
//if it's not ALL of them then an encoded query is probably easiest.
var encQry = 'os=Windows 2003 Standard'; //example query string
//query the cmdb_ci_service_technical table for all of your child records.
var ciRecs = new GlideRecord('cmdb_ci_win_server'); //You'll be querying the "cmdb_ci_service_technical" table here.
ciRecs.addEncodedQuery(encQry);
ciRecs.query();
while (ciRecs.next()) {
//now that we have the children, while loop through them to create the relationship.
var gr = new GlideRecord('cmdb_rel_ci');
gr.initialize();
gr.parent = busApp; //set the parent sys_id to the business application
gr.child = ciRecs.sys_id; //set the child to the sys_id of the CI record
gr.type = '25242fb2377a9200738d021a54990e88'; //sys_id of the "type" of relationship example here is Owns::Owned by
gr.insert();
}
gs.info("Number of relationships created - " + ciRecs.getRowCount());

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2023 02:14 AM
Hi @Naveen87
Why don't you create a import set and prepare an ecel and import at once in the Relationship CI table.
I think that will be the best possible way to achieve this. No scripting, no hassle.
Aman Kumar