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

Thank you David and Kannan for your post.



Ok. If using coalesce. What if I want to replace a child?


Here there is a relation between 1 and A, 2 and B, and so on... I want to replace the the relation where 3 is related to C and replace the "C" with "Q".



Should I then set up multiple coalesce to find the unique record in order to replace the CI "C" with "Q"?



find_real_file.png


Hey,



If you are trying to setup multiple coalesce value then you need to receive the "UUID Parent" and "UUID Child" and the "Replace UUID Child" (This will be your new Child) as well.



Set Coalesce value on UUID Parent and UUID Child and just change the UUID Child with Replace UUID Child.


Hello again Kannan,



As shown in the spreadsheet screen dump above I want to replace C with Q. But I don't think I can have coalesce on both parent and child because that way I will not be able to replace a child. I think I was a bit too fast in my thinking before.



Basically.. If I'm sending in "Q" to be replacing "C" that is related to "3", how should this be done? I don't want to create a new record where 3 is related to C in one record and 3 is related to Q in another record..



I think I need to edit my web service so that it can take old_child and UUID Child in order to know what child record to edit. Then using coalesce I might be able to find the record I'm looking for...