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

Is there a way to copy related items (CI relationships) from one CI to another CI?

humblecommitted
Kilo Guru

Hello Community,

I was wondering if there was a way of copying related CI items from one CI to another. i.e.

Take CI related items from one CI:

find_real_file.png

and copy it to another CI:

find_real_file.png

I would hate to have to replicate these relationships manually:

find_real_file.png

Thanks for your help in advance.

1 ACCEPTED SOLUTION

humblecommitted
Kilo Guru

So it looks like i had to hack it for now.



I had to do a source code injection.



Steps:


open up the relationship items for the table that has all the CI relationships configured all ready.



right click the relationship table to inspect the element.


find_real_file.png


copy the "select id" of the table with the CIs (it should contain the sys_id's of the CI items were trying to copy).


find_real_file.png


paste the string into a code editor in preparation to paste into another ci:


find_real_file.png


Open another CI that you would like to copy the related CI items to:


find_real_file.png


right click on the "select id" segment like in the previous CI and paste the code we copied from the editor here:


find_real_file.png


find_real_file.png


find_real_file.png


Click on one of the items to make the "Apply" button live and register all the updated data that was inputted:


find_real_file.png


And "BAM" easy copied solution for related CIs from one CI to another.


find_real_file.png


View solution in original post

8 REPLIES 8

jake_mckenna
ServiceNow Employee
ServiceNow Employee

There is not a copy button, but you are looking to update the record on the cmdb_rel_ci table. If you find that first CI and replace or copy the new Ci you can technically replicate or replace.


Hello Jake,



Thank you for your prompt response.   I am not sure if this would work in my current situation because the CIs were created from a discovery tool and it captured some important components that it added to the CI so I do not want to lose that information.



I do get what you are saying though and makes sense.   I would love to hear the process that would accomplish what you are recommending.  



Would it be possible if you could describe, in as much detail as possible, the method you are suggesting?


humblecommitted
Kilo Guru

So it looks like i had to hack it for now.



I had to do a source code injection.



Steps:


open up the relationship items for the table that has all the CI relationships configured all ready.



right click the relationship table to inspect the element.


find_real_file.png


copy the "select id" of the table with the CIs (it should contain the sys_id's of the CI items were trying to copy).


find_real_file.png


paste the string into a code editor in preparation to paste into another ci:


find_real_file.png


Open another CI that you would like to copy the related CI items to:


find_real_file.png


right click on the "select id" segment like in the previous CI and paste the code we copied from the editor here:


find_real_file.png


find_real_file.png


find_real_file.png


Click on one of the items to make the "Apply" button live and register all the updated data that was inputted:


find_real_file.png


And "BAM" easy copied solution for related CIs from one CI to another.


find_real_file.png


Yikes that is quite the process. I would have suggested something i feel is simpler such as a find and replace script dealing with Sys_ids.



For Example:



(function copyRels(){


        var copyCI = 'the sys_id of the CI you are wanting to copy';


        var newCI = 'the ci to copy to';


        var gr = new GlideRecord('cmdb_ci_rel');


        gr.addQuery('parent',copyCI);


        gr.query();


        while(gr.next()){


                  gr.parent = newCI;


                  gr.insert();//copy the record!


        }


})();




Not tested, but something you could consider next time.