Get sys_id for relation in cmdb_rel_ci

Henrik Jutterst
Tera Guru

I'm creating a web service where I enable the end user to submit a parent & child UUID in order to mange CI relations to other CIs.

I have added a custom filed in cmdb_ci table called u_uuid, so that I in cmdb_rel_ci can manage (delete and create) records in the table...

But I think I need a bit of help to get started in the script.

The web service is using a transform map with the flelds called u_uuid_parent and u_uuid_child.

What I'm looking to do is this:

  1. Get sys_id for row in cmdb_rel_ci based on input from webservice using u_uuid_child
  2. Remove that row
  3. Create a new relation based on u_uuid_parent and u_uuid_child

find_real_file.png

Fig. 01 - Screen dump from field mapping

I'm assuming this will all go into a transform script that I have related to my web service.

But as I said, I think I need a bit of help to get started.

Kind regards

7 REPLIES 7

Henrik Jutterst
Tera Guru

Anyone with input?


Hi Henrik,



So you basically want to update the parent field of that row? If that is it, then you can simply map it using field mapping having the u_uuid_child field as coalesce value and the parent field being mapped to your u_uuid_parent



Thanks,


Kannan


Hello Kannan and thanks for the post!



What I'm looking to do is this:


  1. Get sys_id for the row in cmdb_rel_ci based on input from webservice using u_uuid_child.
  2. Remove that row
  3. Create a new row in cmdb_rel_ci based on u_uuid_parent and u_uuid_child


I guess this should be done in a script running during the transform map.


Hi Henrik,



By row i think you mean record, incoming import set data will come in rows but data already in a table on SN is a record.



Will there only be one relationship set up for each u_uuid_child? If so then Kannan's solution is correct, you can coalesce on the u_uuid_child and it will replace the parent with whatever data you are importing.



If a u_uuid_child will have more than one relationship then you need a way to identify the specific relationship record you want to amend.