The CreatorCon Call for Content is officially open! Get started here.

DirkRedeker
Mega Sage

Hi

Did you ever worked for a longer time in "Scripts - Background" and clicked the wrong button to lose the hard work you already put into your script (e.g. by closing the browser tab/window, or navigating to a different URL).

If you did, you may have thought about "OMG, how can I restore it?".

There is a very simple and easy way, to get back to the state of the script at the last execution.

 

Scenario:

While working in "> System Definition > Scripts - Background" to try out some code snippets which you execute regularly, you have lost this script and can't get back to it.

When I work on "Scripts - Background", I often use the "Run script" (1) button to execute my script and check for the results (see screenshot below):

find_real_file.png

From the execution results page, I always step back to the script page using the "Back" button of the browser. Maybe you do so like me (see screenshot below). This way, I can always modify my script and run it again and again - until I have the results that I was searching for. 

find_real_file.png

Now, when I lost the page to return to my code, I need to get back to the last execution state.

 

 

Options & steps to recover the last executed script content

1) Copy the executed Script from the "System Log"

You can navigate to "> System Logs > System Log > All" (1) and filter the list for all records with "Source" = "ScriptBackgroundCheck" (2) - see screenshot below. The list of records shown (3), will hold the script executed in "Scripts - Background" in the "Message" (4) column.

find_real_file.png

You can copy/paste the script from this message field via clipboard back to your "Scripts - Background" editor.

 

2) Review the scripts execution history

After each execution of a script from within "Scripts - Background", you will see the link (marked in the screenshot below):

find_real_file.png

Of course, if you already closed this window, you will not have this link anymore. But that does not mean, that the data also disappeared in the background.

Clicking the link will lead my to a record in the "Script Execution History" [sys_script_execution_history] table (see screenshot below).

find_real_file.png

Even if we do not have the link anymore, we can open the list of this table, by navigating to:

> sys_script_execution_history.list

in the Application Navigator in ServiceNow Classic UI (see screenshot below).

find_real_file.png

After sorting the list descending by the "Started" date, you will find your last execution topmost.

NOTE:
If you are not the only developer on your instance, also filter the list by the "Executed by" field to show only your executions.

Open the desired record and copy the script from the "Script" field back into your "Scripts - Background" Editor.

 

 

This way, you will be able to restore/recover a lost script in Scripts - Background

Short and easy - AND sometimes VERY helpful 🙂

 

Let me know your opinion on my article in the comments below. Bookmark this article using the upper right button in this article to donate me with some extra points - you are welcome.

 

Have fun and built something on ServiceNow

Dirk

---------------------------------------------------------------------

If you like to also review my other articles on the ServiceNow Community, please have a look at the overview here:

Overview of my articles

NOTE: The content I provide here is based on my own experiences and does not necessarily represent my employer's views.

Comments
Soumalyo Dasgup
Kilo Guru

Nice one Dirk!!

Version history
Last update:
‎05-25-2020 07:15 AM
Updated by: