- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-01-2018 07:35 AM
Hi,
Can somebody help with the following query where I use a set value from sys_history_set and try to find all history lines in sys_history_line
var hiset = new GlideRecord('sys_history_set');
hiset.addQuery('id', test_sysid);
hiset.query();
while(hiset.next()){
gs.print('Set Id = ' + hiset.getValue('sys_id'));
var hiset = hiset.sys_id;
gs.print('Hiset sysid = ' + hiset);
var line = new GlideRecord('sys_history_line');
line.addQuery('set', hiset);
line.query();
while(line.next()){
gs.print('History Line Id = ' + hiline.getValue('sys_id'));
}
}
It just doesn't return anything - what is wrong with this query ?
Regards
Kim
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-01-2018 01:01 PM
It' because you are trying to query 'id' on the sys_history_set table instead of sys_id.
Try this code and make sure you have a sys ID value for the test_sysid variable:
var hiset = new GlideRecord('sys_history_set');
hiset.addQuery('sys_id', test_sysid);
hiset.query();
while(hiset.next())
{
var his = hiset.sys_id;
//gs.print(his);
var li = new GlideRecord('sys_history_line');
li.addQuery('set', his);
li.query();
while(li.next())
{
gs.print('History Line Id = ' + li.sys_id);
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-01-2018 07:39 AM
You're line var hiset = hiset.sys_id; is going to cause some conflicts...give that variable a new name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-01-2018 10:58 AM
Hi Steve,
Thanks for answering.
I changed the variable name but it still doesn't return anything
Here's the code :
var hiset = new GlideRecord('sys_history_set');
hiset.addQuery('id', test_sysid);
hiset.query();
while(hiset.next()){
var his = hiset.sys_id;
gs.print('Hiset sysid = ' + his);
var li = new GlideRecord('sys_history_line');
li.addQuery('set', his);
li.query();
while(li.next()){
gs.print('History Line Id = ' + li.sys_id);
}
}
Does it take something special to query on the set field in sys_history_line ?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-01-2018 11:37 AM
Where is this script running? is it a fix script, business rule, etc...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā11-01-2018 01:01 PM
It' because you are trying to query 'id' on the sys_history_set table instead of sys_id.
Try this code and make sure you have a sys ID value for the test_sysid variable:
var hiset = new GlideRecord('sys_history_set');
hiset.addQuery('sys_id', test_sysid);
hiset.query();
while(hiset.next())
{
var his = hiset.sys_id;
//gs.print(his);
var li = new GlideRecord('sys_history_line');
li.addQuery('set', his);
li.query();
while(li.next())
{
gs.print('History Line Id = ' + li.sys_id);
}
}