How to populate string field value from one table to another table reference field value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2022 02:45 AM
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
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();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2022 03:07 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2022 03:22 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2022 03:39 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2022 04:16 AM
Script is not working