How to move one table of related list records into another table of related list table

chanikya
Tera Guru

My request is: i would like to see software installation records under  Computers(cmdb_ci_computer)  table of related list table Software installations....

 

In Both tables - Related list table is same (software installation)

Condition: computer table of record name and Arrived computer of record name if it match then only move related table records from Arrived computer table related record's.. 

howcan i do it..

My script is not working....Schedule Jobs

var comp = new GlideRecord('cmdb_ci_computer');
comp.addQuery('u_computername',current.sys_id);
comp.query();
while(comp.next()){
var arc = new GlideRecord('u_arrived_computers');
arc.addQuery('name',comp.name);
arc.query();
if(arc.next()){
var soft = new GlideRecord('cmdb_sam_sw_install');
soft.addQuery('u_computername',arc.sys_id);
soft.query();
while(soft.next()){
gs.log(soft.getRowCount());
soft.u_computername= comp.sys_id;
soft.update();
}
}
}

Here , if you click on computer name it is navigated into Arrived computer table..

find_real_file.png

 

find_real_file.png 

 

 

i wanna see installations record under computer record

find_real_file.png

 

 

if you wanna more information i can explain you clearly .....

please help me here, where i am going wrong here

1 ACCEPTED SOLUTION

So every time you insert or update  computer, it will query the software installation table with computer name field in software installation same as the name of the computer you are creating.

 

var software = new GlideRecord('cmdb_sam_sw_install');
software.addQuery('u_computername.name',current.name);
software.query();
while (software.next())

{

// If it finds the records, it will update the existing archived computer name with the new computer name
software.u_computername = current.sys_id;
software.update();
}


Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

33 REPLIES 33

Kindly help me sanjiv!, please help me  out from this situation

Ok. Relationship is what I would suggest.

But if you want direct relationship, you will have to create a field in software installation table which should be a reference field pointing to computer table.

 

Then you need a After Insert BR in computer table

 

var software = new GlideRecord('software installation table name');

software.addQuery('u_computername.name',current.name);

software.query();

 

while (software.next())

{
software.your_new_field_name_for_computer = current.sys_id;

software.update();

}

 


Please mark this response as correct or helpful if it assisted you with your question.

in the last time we have used  : Installed On (reference field, table: hardware table)

when machine was deleted then that computer record was archived..

so that time we created manual computer record which name is available in Archive table to retrieve installation records  into new one  created computer record 

in Background script , we used this script to populate installation records , it is worked for single record..

 

var comp = new GlideRecord('cmdb_ci_computer');

comp.addQuery('sys_id','6a120b69db2917042beee9525b961903');

comp.query();

while(comp.next()){

var arc = new GlideRecord('ar_cmdb_ci_computer');

arc.addQuery('name',comp.name);

arc.query();

if(arc.next()){

var soft = new GlideRecord('cmdb_sam_sw_install');

soft.addQuery('installed_on',arc.sys_id);

soft.query();

while(soft.next()){

gs.log(soft.getRowCount());

soft.installed_on = comp.sys_id;

soft.update();

}

}

}

 

 

 

If you already have installed on, pointing to computer table, you can use that field as well in the BR script I provided

 

var software = new GlideRecord('cmdb_sam_sw_install');

software.addQuery('u_computername.name',current.name);

software.query();

 

while (software.next())

{
software.installed_on = current.sys_id;

software.update();

}


Please mark this response as correct or helpful if it assisted you with your question.

it is great thing.... installation records are populated under computer record..

 

how the script is working here,    please explain me.....how softwrae records are populated under computer record...

 

var software = new GlideRecord('cmdb_sam_sw_install');
software.addQuery('u_computername.name',current.name);
software.query();
while (software.next())

{
software.u_computername = current.sys_id;
software.update();
}

 

find_real_file.png