
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2018 11:18 PM
Hi all!
I have a set of hardware assets located in alm_hardware that I need to change the related CI of an Asset to another CI. Basically the CI that is related to the asset now is the wrong one and I'm looking for a way to script this change.
Now it loks like this:
Asset tag | Related CI |
---|---|
A1 | C1 |
A2 | C2 |
A3 | C3 |
... | ... |
This is what I'm looking for:
Asset tag | New Related CI | Old Related CI |
---|---|---|
A1 | New C1 | C1 |
A2 | New C2 | C2 |
A3 | New C2 | C2 |
... | ... | ... |
Basically I want to insert a new CI related to the Asset just like Assets and CI's are linked together. And then add a CI relation between "New Related CI" and "Old Related CI" in the cmdb_rel_ci table.
Can someone with a bit of scripting knowledge show me what a script would look like?
I'm looking to send in the "Asset tag" and the "New Related CI" in a set of data
Kind Regards
/Henrik
Solved! Go to Solution.
- Labels:
-
Best Practices
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2021 01:58 AM
Hmm.. this was some time ago, but I think I solved it with this script:
// link CI to Asset just like Assets are linked to CIs
var gr = new GlideRecord('alm_asset'); //create glide record on table
gr.query(); //query all records in table
while(gr.next()) {
var Id = gr.ci; //get sys_id for CI in alm_asset table
var cmd = new GlideRecord('cmdb_ci'); //create glide record on table
cmd.addQuery('sys_id',Id); //where sys_id from cmdb_ci == sys_id from ci on Asset table (Id)
cmd.query(); // run query
if(cmd.next()) {
cmd.asset = gr.sys_id; //update asset field on cmdb_ci table with
cmd.setWorkflow(false); //disable running of business rules that might normally be triggered by subsequent actions
cmd.update(); //commit update
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2018 11:46 PM
Anyone with ideas?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2021 01:16 PM
I need to do something very similar. I need a script that would move a relationship from one asset to another and then delete the old asset.
I am already finding duplicates on serial number in alm_hardware with a script. Now I need to act on them based on one asset having a related CI and the other asset not having a related CI. Then move the CI relationship to the latter.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-19-2021 01:58 AM
Hmm.. this was some time ago, but I think I solved it with this script:
// link CI to Asset just like Assets are linked to CIs
var gr = new GlideRecord('alm_asset'); //create glide record on table
gr.query(); //query all records in table
while(gr.next()) {
var Id = gr.ci; //get sys_id for CI in alm_asset table
var cmd = new GlideRecord('cmdb_ci'); //create glide record on table
cmd.addQuery('sys_id',Id); //where sys_id from cmdb_ci == sys_id from ci on Asset table (Id)
cmd.query(); // run query
if(cmd.next()) {
cmd.asset = gr.sys_id; //update asset field on cmdb_ci table with
cmd.setWorkflow(false); //disable running of business rules that might normally be triggered by subsequent actions
cmd.update(); //commit update
}
}