copy a field value on a table to another table's field, using a reference from the original table.

mattmm1
Tera Contributor

Hi,

I have a table called 'u_iar' which references the 'name' field on the 'cmdb_ci_business_app' table (this is called 'configuration_item' on the origin table and 'name' on the reference table ) as well as having it's own , separate 'name' field on the origina table (yes, I know this is poor practice) with the exact same value . The referenced name field matches the original tables name field currently, despite having no relationship referentially.

mattmm1_0-1702460118571.png

 

on the 'u_iar' table I have a field called 'platform_manager'

on the 'cmdb_ci_business_app' app table I have a field called 'x_enps_iar_applica_platform_manager'

 

I am wanting to copy the value in 'u_iar.platform_manager' to the 'cmdb_ci_business_app.x_enps_iar_applica_platform_manager' field.

 

In order to test this I am doing an addQuery on a single record and using background scripts as per below to no avail with the error

Cannot read property "x_enps_iar_applica_platform_manager" from undefined
var gr = new GlideRecord("x_enps_iar_applica_cmdb_ci_information_asset");
var ci = gr.configuration_item
gr.addQuery('name','Member Mobile App')
gr.query();
gr.initialize();
ci.x_enps_iar_applica_platform_manager.name = gr.platform_manager.name;
//add remaining fields as is
gr.update();

 

any help, greatly appreciated. In a past life I was a dev, but has been too many years in between!

2 REPLIES 2

Pradnyesh
Kilo Sage

 

  1. First Glide the u_iar table and find that record using addQuery.
  2. Then store that record platform_manager value (sys_id) in one variable. (eg.  var a = 12345)
  3. Glide the second table.
  4. Find out the record in that table using addQuery.
  5. And set that variable to it. (eg.  gr.x_enps_iar_applica_platform_manager = a)
  6. Update the record. (eg.  gr.update();)

Thanks @Pradnyesh . I'm wanting to do this via the reference field (i.e. the configuraiton_item field on the u_iar table, which is a reference to the second table). This is so I can be sure I am referencing each record correctly from it's u_iar table to the cmdb_ci_business_app table. While I'm testing this on one reference, I plan to eventually do this on the entire table.