- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2018 05:49 AM
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..
i wanna see installations record under computer record
if you wanna more information i can explain you clearly .....
please help me here, where i am going wrong here
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2018 01:15 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2018 01:15 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2018 04:07 PM
Please mark this thread answered if works for you now.
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-02-2018 11:14 PM
Thanks Sanjiv!
it's great help for me
Thanks a lot!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2018 09:44 AM
Sanjiv,
small favor, if serial number record already existed in computer table then should not created new record with same serial number in computer table .
Script is not working..............
Br Script: before table:cmdb_ci_computer
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var tbl = new GlideRecord('cmdb_sam_sw_install');
tbl.addQuery('u_serialnumber', current.serial_number);
tbl.query();
if (tbl.next() && tbl.sys_id != current.sys_id) {
gs.addErrorMessage("Serial number already exists");
current.setAbortAction(true);
}else
{
while (tbl.next())
{
tbl.u_computername = current.sys_id;
tbl.update();
}
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2018 10:08 AM
Please use below script and it should be an on insert BR
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var tbl = new GlideRecord('cmdb_sam_sw_install');
tbl.addQuery('u_serialnumber', current.serial_number);
tbl.query();
if (tbl.next()) {
gs.addErrorMessage("Serial number already exists");
current.setAbortAction(true);
}else
{
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();
}
}
})(current, previous);
Please mark this response as correct or helpful if it assisted you with your question.