Fix Script to change sys ids of Asset and CI
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2018 05:42 AM
Hello All,
One asset is associated with one CI, but I have another CI which has to be associated to this asset.
For example: I have Asset "XYZ" and it has related CI "XYZ". But there is another CI "ABC".
Now this Asset "XYZ" has to be related to CI "ABC".
My requirement is, I should keep the sys_id of Asset XYZ in the asset field of CI ABC and should remove the sys_id of asset xyz from the CI XYZ.
Can anyone please help with script in fix script.
Thanks in advance.
- Labels:
-
Best Practices
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2018 06:23 AM
It would go something like this:
Standard disclaimer: The following code is untested, requires review and potential modifications.
(function () {
// Clear out old asset value of CI XYZ
var ci1 = new GlideRecord('cmdb_ci');
if (ci1.get('asset', 'SYS_ID_OF_ASSET_XYZ')) {
ci1.asset = '';
ci1.update();
}
// Set the value of the new GlideRecord
var ci2 = new GlideRecord('cmdb_ci');
if (ci2.get('SYS_ID_OF_CI_ABC')) {
ci2.asset = 'SYS_ID_OF_ASSET_XYZ';
ci2.update();
}
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2018 07:22 AM
Thanks for your help, what would be the best practice if I want change sys_id's for more records at least 50 records.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2018 08:30 AM
Use an array or query for the records in a loop, then iterate over each record. It sounds like you need to know three bits of information:
- Original CI
- New CI
- Asset
That implies you have a list somewhere of those elements or you can query for them. While it's easy to query for the CI that currently as the asset, I don't yet understand how you would get a list of New CIs that you want to assign the asset to.