The Now Platform® Washington DC release is live. Watch now!

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
andrew_venables
ServiceNow Employee
ServiceNow Employee

Wow, what a great new capability this is!

Introduced in London we now have the ability to view script execution histories and even roll them back!

Have you ever run a background script, had it finished executing and clicked away before making a note of the result, sound familiar? Well now you can view the history of your script executions!

Even better tho, have you ever accidentally run a background script and then instantly regretted it? Maybe you had a typo in your addQuery and updated more records that you intended? Well now the script execution gives you the ability to roll back the script, including the changes it made to instance data.

Lets see it in action, with a simple script to update incident records,

find_real_file.png

After the script is run, we now have some additional output above the script:

find_real_file.png

If we click on the "available here" link at the top we are taken to the Script Execution History record that has been generated. These are stored in the sys_script_execution_history table whenever a background script is run with the "Record for rollback?" checkbox checked. We can also view a list of these script execution histories by typing sys_script_execution_history.list in the left navigation bar.

The Script Execution History record has lots of information on the script that was run:

find_real_file.png

Specifically we can see the start and finish time, the instance node, script that was run and the output. There's also some information on the number of SQL transactions, processing time etc. 

 

Now let's take a look at the list of open incidents on the instance, as you can see below, all the open incidents on the instance have been updated with the same short description - oops!

Even worse we can see that all of the Caller fields have been set to empty, this must be caused by some logic (probably a business rule) on the incident table. 

 find_real_file.png 

 

So lets roll back this script by using the new rollback script execution functionality, to do this on the Script Execution History form there is a Rollback Script Execution... under the Related Links list.

Select this action and a new dialog will open asking you to confirm your choice, 

find_real_file.png

Type yes in the dialog box and click ok.

A progress bar will appear and show you the progress of the rollback:

find_real_file.png

When it's complete, check the list of records again to verify the rollback is successful,

find_real_file.png

Crucially, not only has the short description been returned to the previous value but the caller field has been re-populated. The rollback will reverse the whole transaction, not just the field that was actually changed in the script. 

 

Perfect! The rollback has worked and the records have been restored so we can be more careful next time when we run scripts 🙂

 

Great, now we have a mechanism to audit, review and rollback the background scripts that are run.

Happy scripting.

 

Note: The Script Execution History [sys_script_execution_history] table has an Auto Flush rule configured on it meaning entries will be removed after 7 days. If you want to keep the history longer than that you can alter this rule in the sys_auto_flush table to a higher age.

6 Comments