Create link from CI to Asset

Henrik Jutterst
Tera Guru

Can someone please help me here?

We have manually imported CI and Assets into CMDB. This was done at two separate occasions. First we imported the CIs without relation to an Asset and then we imported the Assets that had relation to CIs.

This resulted in that I can see relating CI from an Asset, but not relating Asset from a CI. Now I need to relate the ~10 000 CIs with the once that have an Asset. How can this be done?

Anyone that can help out with a background script on this?

I did take a look on this page:

Asset and CI management

I know there are some business rules that run in the background when creating Assets or CI.

  • Update CI fields on change (on the Asset [alm_asset] table)
  • Update Assets on change (on the Configuration Item [cmdb_ci] table)
1 ACCEPTED SOLUTION

HI Henrik,



Now what you have to do is write a one time script.



You will have to query on asset able and take value of CI field and then query CI table and update Asset field on CI Table.



See below script:



var gr = new GlideRecord('alm_asset');


gr.query();


while(gr.next())


{


var Id = gr.ci;



var cmd = new GlideRecord('cmdb_ci');


cmd.addQuery('sys_id',Id);


cmd.query();


if(cmd.next())


{


cmd.asset = gr.sys_id;


cmd.setWorkflow(false);


cmd.update();


}


}



Thank you,


Ashutosh


View solution in original post

9 REPLIES 9

Ashutosh Munot1
Kilo Patron
Kilo Patron

Hi Henrik,



I have one question. Please help me through this.



What do you mean when you say you have link from CI to Asset and not from Asset to CI.



How you imported asset CI relation ship.



Thank you,
Ashutosh


Please look at my comment to David below.


Dave Smith1
ServiceNow Employee
ServiceNow Employee

This resulted in that I can see relating CI from an Asset, but not relating Asset from a CI. Now I need to relate the ~10 000 CIs with the once that have an Asset. How can this be done?


I understood it to be the other way around: models create the relationships between assets and CIs, but they're a definition attached to an asset that determines if a CI will be related or not, and how changes should propagate.



The process should have been:


  1. define models for the assets, along with the relationships
  2. import assets, letting them create CIs
  3. import CIs, letting them update CI attributes


It sounds like you've done 2 and 3 in isolation and are now seeking to manually redo the work that models will have done for you back at stage 1.


Here are two screenshots from the same CI and Asset.



find_real_file.png


Fig 01 - Asset. The CI is linked to this Asset an can be reached from the Asset.



find_real_file.png


Fig. 02 - CI. The CI from Fig. 01 but here there is no connection to the Asset.