Requesting help in scheduled job script

Supriya25
Tera Guru

Hi Team,

 

I have ran Scheduled Job script in Background script for testing, but not sure why it is NOT working properly .

var arr=[];
var gr = new GlideRecord('Scoped application Table name');

gr.addEncodedQuery('State is not Resolved,Closed, Cancelled');

gr.query();

while(gr.next()){

gs.info('Gate 1 '+gr.sys_id);

arr.push(gr.sys_id);

}

gs.info("Array Length "+arr.length); // getting result 30, which is correct

for(var i=0;i<arr.length;i++){

var ttgr = new GlideRecord('sys_history_line');

ttgr('oldISNOTEMPTY^set.id='+arr[i]);

ttgr.query();

if(ttgr.next())

{

gs.info('Gate 2 '+ttgr.set+"  "+arr[i]); // here I'm getting only 5-sysID details  , which is wrong

}
}

why system giving 5-sysId details only out of 30 -sysID's  from Second loop, I'm not understanding why this wrong result coming.

 

 

when I search sysID directly in sys_history_line table there data is available, but not resulting from Script.

 

12 REPLIES 12

may be there are some flow in script performing the record lookup in the sys_history_line table.

ttgr.addEncodedQuery('oldISNOTEMPTY^set.id='+arr[i]); appears to confusing to me.
Unfortunately, without the right context , not able to provide direct script.
Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning ‌‌
Thanks & Regards 
Deepak Sharma 

Hi,
Let's take Incident table we have 900+ history record are here

Supriya25_0-1714544155003.png

 

 

var arr=[];
var gr = new GlideRecord('incident');
gr.addEncodedQuery('state=1');
gr.query();
while(gr.next()){
gs.info('Gate 1 '+gr.sys_id);
arr.push(gr.sys_id);
}
gs.info("Array Length "+arr.length); 


for(var i=0;i<arr.length;i++){
var ttgr = new GlideRecord('sys_history_line');
ttgr.addEncodedQuery('set.id='+arr[i]);
ttgr.query();
if(ttgr.next())
{
gs.info('Gate 2 '+ttgr.set+"  "+arr[i]); 
}
}

 

 


which I'm runing , Output is below :

 

 

*** Script: Gate 1 471bfbc7a9fe198101e77a3e10e5d47f
*** Script: Gate 1 0c5f3cece1b12010f877971dea0b1449
*** Script: Gate 1 552c48888c033300964f4932b03eb092
*** Script: Gate 1 57af7aec73d423002728660c4cf6a71c
*** Script: Gate 1 78271e1347c12200e0ef563dbb9a7109
*** Script: Gate 1 85071a1347c12200e0ef563dbb9a71c1
*** Script: Gate 1 965c9e5347c12200e0ef563dbb9a7156
*** Script: Gate 1 a623cdb073a023002728660c4cf6a768
*** Script: Gate 1 a83820b58f723300e7e16c7827bdeed2
*** Script: Gate 1 ed92e8d173d023002728660c4cf6a7bc
*** Script: Gate 1 f12ca184735123002728660c4cf6a7ef
*** Script: Gate 1 ff4c21c4735123002728660c4cf6a758
*** Script: Gate 1 a2496c05731110107418660c4cf6a711
*** Script: Gate 1 a9e30c7dc61122760116894de7bcc7bd
*** Script: Gate 1 d71da88ac0a801670061eabfe4b28f77
*** Script: Array Length 15
*** Script: Gate 2 726ab74b97f9021014e4f93de053afa2  d71da88ac0a801670061eabfe4b28f77
*** Script: Gate 2 726ab74b97f9021014e4f93de053afa2  d71da88ac0a801670061eabfe4b28f77
*** Script: Gate 2 726ab74b97f9021014e4f93de053afa2  d71da88ac0a801670061eabfe4b28f77
*** Script: Gate 2 726ab74b97f9021014e4f93de053afa2  d71da88ac0a801670061eabfe4b28f77
*** Script: Gate 2 726ab74b97f9021014e4f93de053afa2  d71da88ac0a801670061eabfe4b28f77
*** Script: Gate 2 726ab74b97f9021014e4f93de053afa2  d71da88ac0a801670061eabfe4b28f77
*** Script: Gate 2 726ab74b97f9021014e4f93de053afa2  d71da88ac0a801670061eabfe4b28f77
*** Script: Gate 2 726ab74b97f9021014e4f93de053afa2  d71da88ac0a801670061eabfe4b28f77
*** Script: Gate 2 726ab74b97f9021014e4f93de053afa2  d71da88ac0a801670061eabfe4b28f77
*** Script: Gate 2 726ab74b97f9021014e4f93de053afa2  d71da88ac0a801670061eabfe4b28f77
*** Script: Gate 2 726ab74b97f9021014e4f93de053afa2  d71da88ac0a801670061eabfe4b28f77
*** Script: Gate 2 726ab74b97f9021014e4f93de053afa2  d71da88ac0a801670061eabfe4b28f77
*** Script: Gate 2 726ab74b97f9021014e4f93de053afa2  d71da88ac0a801670061eabfe4b28f77
*** Script: Gate 2 726ab74b97f9021014e4f93de053afa2  d71da88ac0a801670061eabfe4b28f77
*** Script: Gate 2 726ab74b97f9021014e4f93de053afa2  d71da88ac0a801670061eabfe4b28f77

 

 

 

exact issue repeating in client instance too. 
if we take  "a623cdb073a023002728660c4cf6a768" don't have any info message  from second loop 'sys_history_line' in OUTPUT.

data existed  in table  , so script it has to check and return info message from second loop sys_history_line block  right. but it is not happening 

Supriya25_1-1714545047291.png

 

I hope these details will give you better information to help me