Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Best practice for updating Asset fields during CI Transform Map import?

4886talga
Tera Contributor

Hi everyone,

I am importing server data into the cmdb_ci_server table using a Transform Map. The CIs are creating correctly, and the corresponding Assets are being generated automatically in alm_hardware.

I need to map 4 specific fields from my import set (u_account, u_account_address, u_stockroom, u_service_organization) directly to the Asset record, not the CI.

I tried using an onComplete script, but it seems the Asset records aren't fully created/linked by the time the script runs, so the updates aren't sticking.

Does anyone have a recommended approach for this? Should I be using an onAfter script with a GlideRecord to the alm_hardware table, or is there a way to ensure the Asset is created synchronously so I can dot-walk to it?

Thanks in advance!

2 REPLIES 2

Sneha KH
Tera Guru

 

Hello @4886talga ,

  • Identify the CI: Use target.sys_id.
  • Find the Asset: Query the alm_hardware table where the ci field matches your target CI.
  • Update the Fields: Apply your 4 specific fields.

Example Script

Place this in the Table Transform Map under the Transform Scripts tab:

  • (function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
    // 1. Find the Asset linked to the current Target CI
    var assetGr = new GlideRecord('alm_hardware');
    assetGr.addQuery('ci', target.sys_id); 
    assetGr.query();
    if (assetGr.next()) {
    // 2. Map your custom fields from the Import Set (source) to the Asset (alm_hardware)
    assetGr.u_account = source.u_account;
    assetGr.u_account_address = source.u_account_address;
    assetGr.stockroom = source.u_stockroom; // Ensure the backend name matches
    assetGr.u_service_organization = source.u_service_organization;

    // 3. Update the Asset record
    assetGr.update();
    }
    })(source, map, log, target);

Pratiksha
Mega Sage

Hi @4886talga

 

The asset creation takes a little time. It create asset on insert via BR.  I would suggest to create it other way around. Create asset first and then CI. Also, its not best practice to upload data in cmdb_ci_server table. Try to update data in to the correct class like windows server or linux server. When you are doing this, you need to understand two important things. Models and model categories. They decide how CI will created. If their are fields which is not present on asset form then you have to think about creating a separate ETL ( use IHETL). 

 

Regards,

Pratiksha