- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2021 06:12 AM
var gr = new GlideRecord("change_request")
gr.query();
while(gr.next()) {
var line = new GlideRecord("sys_history_line");
line.addQuery('set.id',gr.sys_id);
line.setLimit(1);
line.query();
if(line.next()){
gs.print('CHG: ' + gr.number.toString() + ', Set ID: ' + line.set.id.toString());
}
else{gs.print('CHG: ' + gr.number.toString() + ', Set ID: ' + line.set.id.toString());
}
}
What could be wrong in this script? What I am trying to do is validate if all CHG number has a corresponding sys_history_line entry.
When I try to run this script, it doesn't match the set IDs.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2021 06:59 AM
Hi,
Open any change and run the History->Line command and generate the record in sys_history_set table until the set table will not have any history record.
Refer the below links
Scripts: GlideRecord sys_history_set / sys_history_line / sys_audit
Thanks,
Ashish
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2021 10:19 AM
Separating the history_set and history_line steps into 2 queries will help with troubleshooting and cover all scenarios. The below script will more clearly show you every change record, and whether or not they have a history line (or a history set without a history line - possible, but not likely).
var chg = new GlideRecord('change_request');
chg.orderBy('number');
chg.query();
while(chg.next()){
var hset = new GlideRecord('sys_history_set');
hset.addQuery('table', 'change_request');
hset.addQuery('id', chg.sys_id.toString());
hset.query();
if(hset.next()){
var line = new GlideRecord('sys_history_line');
line.addQuery('set', hset.sys_id.toString());
line.setLimit(1);
line.query();
if(line.next()){
gs.print('History line found CHG: ' + chg.number.toString() + ', Set ID: ' + hset.id.toString());
}
else{
gs.print('History set found, but no line CHG: ' + chg.number.toString());
}
}
else{
gs.print('No history set found CHG: ' + chg.number.toString());
}
}