How to populate string field value from one table to another table reference field value

ak49
Tera Contributor

Hi There,

There is cmdb_ci table and class is compute and I took any random record and as per screenshots there is name field value. You can see that. so that value I want to populate on hardware table there is configuration item reference field there I need to populate. I have existing BR and I checked there is need to do some change but I did it but it's not working please help me on this. I have provided the script below

image

find_real_file.png

image

below script

var as = new GlideRecord('alm_asset');
as.addQuery('sys_id',current.asset);
as.query();

 

if(as.next()){
as.install_status = current.install_status;
as.u_secondary_or_support = current.u_secondary_or_support;
as.u_offline_device = current.u_offline_device;
as.u_model_number = current.model_number;
as.u_last_altiris_feed_date = current.u_last_altiris_feed_date;
as.u_last_altiris_feed_id = current.u_last_altiris_feed_id;
as.ci = current.name;
as.insert();
as.update();
}

 

9 REPLIES 9

Dan H
Tera Guru

Do you have a CI with the same name? Example:lw5rq53j3? Can you show the CI record for the same

The reason why your changes aren't working is because you're giving a string 'lw5rq53j3' to a reference field which wants a Sys id.

 

Hope this helps

Please mark my answer as Correct/Helpful based on impact

Regards,

Dan H

ak49
Tera Contributor

If I search 'lw5rq53j3' in the configuration item field I am able to see that but I don't want to do it manually I want auto populate

 

Please try the following:

Script:

var as = new GlideRecord('alm_asset');
as.addQuery('sys_id',current.asset);
as.query();

function getCiSysid(){
 var cmdbciGr = new GlideRecord('cmdb_ci');
 cmdbciGr.addQuery('name', current.name);
 if(cmdbciGr.next()){
gs.log('CI DEBUG, found a record');
     return cmdbciGr.sys_id;
 }
}


if(as.next()){
as.install_status = current.install_status;
as.u_secondary_or_support = current.u_secondary_or_support;
as.u_offline_device = current.u_offline_device;
as.u_model_number = current.model_number;
as.u_last_altiris_feed_date = current.u_last_altiris_feed_date;
as.u_last_altiris_feed_id = current.u_last_altiris_feed_id;
as.ci = getCiSysid();
as.insert();
as.update();
}

Hope this helps

ak49
Tera Contributor

Script is not working