Anurag Tripathi
Mega Patron
Mega Patron

 

Picture1.jpg

How many times has it happen to you that you write a background script and loose it for one of the following reasons:

  • Close the browser by mistake.
  • Session times out and must re login and you lose the script.
  • At some point later realized you need the script back.

 

 

Worry no more as that script is not lost and you can get it back from the sys_script_execution_history table

 

Not only this you can also Rollback any* changes done by this script

Picture2.jpg

 

Lets look at an example: Run this in a background script

 

 

 

var testGR = new GlideRecord('incident');
testGR.get('25b66ea12f0b7550fb09ad2ef699b6bc'); //use sys_id of incident on your instance
testGR.state= 2;
testGR.work_notes = 'This is for SN community blog';
testGR.update();

 

 

 

Check the result Result:

Picture3.png

 

Now Lets see how can you recover the script if you lost it

 

From the menu -> Now Navigate to Rollback & Recovery -> Script Execution History (sys_script_execution_history)

Picture4.png

 

Useful Data in Table : This table holds the scripts executed and you can come here to recover the script if you lost it or closed the window or something.

Not just this you can also see

  • Who ran the script
  • Start and end time

Picture5.png

 

PS: This table is flushed every 7 days so you won't get data older than that.

 

Drilling in, you can get more info on the SQL Count, SQL Time and Also the Processing & Response times (in milliseconds)

  • SQL Count: Total SQL Commands executed
  • SQL Time: Time Taken by SQL Commands in Milliseconds
  • Transaction Processing Time:  This is the processing time of the transaction, and this does not include the time taken waiting for a worker
  • Response Time: Response Time in Milliseconds

Picture6.png

Furthermore, you can see the number of tables where the data was inserted/updated. Directly or indirectly. For the example we have we just update the work notes and state but here you can see that form the backend there are 5 tables where data is inserted/updated.

Picture7.png

 

 

Now let’s Rollback this script.

 

To Rollback the same form has a little related link as shown below

Picture8.png

 

Clicking on the same gives confirmation to proceed.

Picture9.png

 

Enter 'yes' and proceed.

Picture10.png

 

Validating results

  • I went back to the incident and saw that the state was reverted to original state
  • It still shows the journal entry that state was updated, but no journal entry for state revering.
  • The work notes entered are still present on the Incident and it is not reverted.

 

 

Summary

  • This is a handy place to recover the background script, which I often loose.
  • Good to rollback changes on records.
  • This can rollback some basis changes not very efficient as it cannot rollback journals or emails triggered etc.