Finding old value of a field

samadam
Kilo Sage

I have a requirement to pull the old value of a filed which was updated on a particular date. Tried to query the sys_audit table but transactions are failing. What is the best option to do this?

5 REPLIES 5

Nate Aiken
Tera Expert

If the field is not audited, the only other way I know of at this time to get the old value would have been with a business rule at the time of change.   The value in the table has been overwritten and at this point may not be retrievable.



Nate Aiken


Senior Solution Architect


Evergreen: IT that aims higher



PS: Please hit Like, Helpful or Correct depending on the impact of the response


Stijn Verhulst3
Kilo Guru

Hi Sam,



2 options you can try:



- Change the Quota Rule for UI Transactions: Default quota rules



- When you open up the sys_audit table, wait until you get the transactions failing message appears again and immediately afterwards try again. Some caching will be applied which might open up the list of audit records quicker (often in my case but not always).



But as Nate already pointed out, make sure first the table is being audited (can be done by checking the "collection" record of the table in the System Dictionary); otherwise no activities will be kept in the platform for the specifc table records.



Hope this helps you forward,



Stijn


samadam
Kilo Sage

Thank you. The field is being audited. I will try the sys_audit table again.


Stijn Verhulst3
Kilo Guru

Sam,



forgot another option...



You can also apply this script to retrieve all of the changes for a given field on a particular record. It can be executed by going to the module "Scripts - Background" in the platform (as long as you're an administrator). Just don't foget to fill in the query data highlighted by <...> within the code:



// *** START OF CODE ***


var auditRec = new GlideRecord('sys_audit');


auditRec.addQuery('documentkey', '<SYS ID of the record>');


auditRec.addQuery('tablename', '<table name of the record>');


auditRec.addQuery('fieldname', '<field name>');


auditRec.query();




while (auditRec.next()) {


      gs.print("Value changed from " + auditRec.oldvalue + " to " + auditRec.newvalue + " on " + auditRec.sys_created_on);


}


// *** END OF CODE ***



Kind regards,



Stijn