How to revert a record to original values?

amala2
Mega Guru

Hi,

I've a requirement where I want to revert all the fields in an incident record to the original value. The original value whcih it had while insertion.

Thanks

2 REPLIES 2

Aman Kumar S
Kilo Patron

How do you want to do it, do you want it to happen for all the records or want a one time action for record of user's choosing?

Depending on the scenario you will need to create a Fixed script or scheduled job, and for 2nd scenario you can build up a UI action, so user can restore value for a particular record.

The solution will work by looking at "sys_audit" table

Best Regards
Aman Kumar

This is an example which I tried out:

var gr = new GlideRecord('incident');
gr.addQuery('sys_id','13c8955587945550cfdd2f49cebb3554');
gr.query();
if(gr.next())
{
    var audit = new GlideRecord('sys_audit');
    audit.addQuery('documentkey','13c8955587945550cfdd2f49cebb3554');
    audit.query();
    if(audit.next())
    {  
        for(var i = 0;i<audit.getRowCount();i++)
        {
             gr[audit.fieldname] =  audit.oldvalue;
        }
        gr.update();
        
    }
}

I know the placement of gr.update() in the above script should be inside for loop. But I want the update on the target record at once, not separately

How can I achieve it?