How to get Old values and populate in Target record

Supriya25
Tera Guru

Hi Team,

 

I'm trying to re-populated 4-field of old values in INC record( Resolved by, Resolved , Summary of Resolution ), so I'm trying to Query sys_history_line table and INC table

how Query, how to populated old values into Respective INC Target fields from sys_history_line.

Please help with some sample code here.

7 REPLIES 7

DrewW
Mega Sage
Mega Sage

You need to look at the sys_audit table for the information you are looking for.  The sys_history_line table only has data after you view the history of a record and the system deletes it every time you view the history or it gets to a certain age.

 

hi ,
there I have only today's data only, but unfortunately it's not working below code, 
Code not checking every SysID

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.addQuery('set.id', arr[i]);
// ttgr.addNotNullQuery('old');
ttgr.query();

while (ttgr.next()) {
gs.info('Gate 2 ' + ttgr.getDisplayValue('set') + " " + arr[i]);
}
}
OUTPUT :  Incident: INC0000054 d71da88ac0a801670061eabfe4b28f77 coming every time
[0:00:00.534] Script completed in scope global: script


Script execution history and recovery available here


*** 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 Incident: INC0000054 d71da88ac0a801670061eabfe4b28f77
*** Script: Gate 2 Incident: INC0000054 d71da88ac0a801670061eabfe4b28f77
*** Script: Gate 2 Incident: INC0000054 d71da88ac0a801670061eabfe4b28f77
*** Script: Gate 2 Incident: INC0000054 d71da88ac0a801670061eabfe4b28f77
*** Script: Gate 2 Incident: INC0000054 d71da88ac0a801670061eabfe4b28f77
*** Script: Gate 2 Incident: INC0000054 d71da88ac0a801670061eabfe4b28f77
*** Script: Gate 2 Incident: INC0000054 d71da88ac0a801670061eabfe4b28f77
*** Script: Gate 2 Incident: INC0000054 d71da88ac0a801670061eabfe4b28f77
*** Script: Gate 2 Incident: INC0000054 d71da88ac0a801670061eabfe4b28f77
*** Script: Gate 2 Incident: INC0000054 d71da88ac0a801670061eabfe4b28f77
*** Script: Gate 2 Incident: INC0000054 d71da88ac0a801670061eabfe4b28f77
*** Script: Gate 2 Incident: INC0000054 d71da88ac0a801670061eabfe4b28f77
*** Script: Gate 2 Incident: INC0000054 d71da88ac0a801670061eabfe4b28f77
*** Script: Gate 2 Incident: INC0000054 d71da88ac0a801670061eabfe4b28f77
*** Script: Gate 2 Incident: INC0000054 d71da88ac0a801670061eabfe4b28f77
*** Script: Gate 2 Incident: INC0000054 d71da88ac0a801670061eabfe4b28f77
*** Script: Gate 2 Incident: INC0000054 d71da88ac0a801670061eabfe4b28f77
*** Script: Gate 2 Incident: INC0000054 d71da88ac0a801670061eabfe4b28f77
*** Script: Gate 2 Incident: INC0000054 d71da88ac0a801670061eabfe4b28f77
*** Script: Gate 2 Incident: INC0000054 d71da88ac0a801670061eabfe4b28f77
*** Script: Gate 2 Incident: INC0000054 d71da88ac0a801670061eabfe4b28f77
*** Script: Gate 2 Incident: INC0000054 d71da88ac0a801670061eabfe4b28f77

  


if we take  "a623cdb073a023002728660c4cf6a768" don't have any info message  from second script block 'sys_history_line' in OUTPUT.

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

Supriya25_0-1714567311447.png

 

 

 

Like I said, you cannot use History Line for what you are trying to do.  You need to use sys_audit to get the information you are looking for.

 

same issue coming with sys_audit table too. I tried it as well.