Create assets automatically when there is new record in cmdb_ci root table

mateuszgrzeskow
Tera Expert

Hello everyone,

 

In our project we have imported the product models and prepared model categories and now we are importing CIs into cmdb_ci table (the root one, without any class).

 

I tried to create model category which would link cmdb_ci and alm_asset but CI class field does not accept the cmdb_ci table. Is it possible to work around it, so that if there is any new record in the cmdb_ci there is also a new record referenced in alm_asset?

 

It works with any other cmdb_ci table, but not the root one.

 

1 ACCEPTED SOLUTION

Ashok Sasidhara
Tera Sage
Tera Sage

We should never create assets for everything populated in cmdb_ci. All CIs are not assets. That is why asset creation should be controlled using the relevant model category or model records as per ServiceNow best practices.

 

View solution in original post

3 REPLIES 3

Samaksh Wani
Giga Sage
Giga Sage

Hello @mateuszgrzeskow 

 

You need to create a Flow Designer for this requiremernt.

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it Helpful.

 

Regards,

Samaksh

pratiksha5
Mega Sage

If you want to write script then you can use the following (function() {
var cmdbCi = current; // Get the new cmdb_ci record

// Create a new alm_asset record
var almAsset = new GlideRecord('alm_asset');
almAsset.initialize(); // Initialize the record

// Set the fields in the alm_asset record based on cmdb_ci
almAsset.name = cmdbCi.name; // Set the name field
almAsset.description = cmdbCi.description; // Set the description field
// Set other fields as needed

// Insert the alm_asset record
var almAssetSysId = almAsset.insert();

gs.info("New alm_asset record created with sys_id: " + almAssetSysId);
})();

 

Ashok Sasidhara
Tera Sage
Tera Sage

We should never create assets for everything populated in cmdb_ci. All CIs are not assets. That is why asset creation should be controlled using the relevant model category or model records as per ServiceNow best practices.