Query the table sys_audit

User149490
Tera Contributor

Hi,

I try to query the sys_audit table to get an old value from a specific field. My proble is the documentkey field. In this field is stored the sys_id from the record. When I use the sys_id directly, I got my result. When I use g_form.getUniqueValue(), I got no result. I use this code:

//var dockey= 'c623ccd3db625bc4dcaefe9b0c961958';    (sys_id from the record)
    var dockey = g_form.getUniqueValue();
    var olddx = new GlideRecord('sys_audit');    

    olddx.addQuery('tablename', 'u_kodak_dx_numbers');
    olddx.addQuery('fieldname', 'u_location');
    olddx.addQuery('documentkey', dockey);
    olddx.query();

    while(olddx.next()) {
        
        alert(olddx.oldvalue + ' dx audit');
    }

Have anybody an idea where my mistake is?

 

Best regards

André

1 ACCEPTED SOLUTION

Ok. You can easily do that using an After update business rule.

 

For ex if you changed the location, you can use

 

gs.addInfoMessage('+++current location++++'+current.u_location);

gs.addInfoMessage('+++old location++++'+previous.u_location);


Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

6 REPLIES 6

SanjivMeher
Kilo Patron
Kilo Patron

Are you using a client script? Because g_form.getUniqueValue() will only work on client script.


Please mark this response as correct or helpful if it assisted you with your question.

User149490
Tera Contributor

yes I´m using a client script

Can you tell me the reason you are using a client script. What is the use case?

I would suggest not querying the sys_audit table from client script, because it is a huge table and it can slow down the performance. Instead use an async business rule. But depends on what you are trying to do.


Please mark this response as correct or helpful if it assisted you with your question.

User149490
Tera Contributor

Okay, the use case is: If I delete an entry in a specific field on a form, I have to set back a specific value on another table to the old value after saving. Therefor I need the old value from this deleted entry because thats the reference to the other table.