logo

NJP

Running Fix Scripts from Update Set

Import · Aug 10, 2015 · article

If you use Fix Scripts you know that after transferring an application or Update Set we have to manually run them. It is often inconvenient to go to the Fix Scripts table, look for necessary scripts, run each one and wait. Moreover, it is so boring to repeat those actions when you have more than a few scripts. Not mentioning the case when you must execute a fix script and forget to do it at all

It would be easier to have a single interface to run all the necessary scripts. In addition, it is much more convenient to be able to access it directly from the Update Set form after the update set is commited.

WHAT WE WANT

Let us create a form that will be opened by 'Run Fix Scripts' button. The button will be visible after a user successfully commits an Update Set and only for admin users.

The form should have a table containing all active fix scripts and useful information (e.g. Description). A user should have an option to select scripts he wants to run. In addition, we need to be able to select how to run the scripts (async or in order).

The last thing we need is a log field with results of script execution.

So our solution should work and look like the diagram below:

image

WHAT WE DO

We implement all our logic in one UI Action and one UI Page. The first step is to add new button 'Run Fix Scripts' on the Retrieved Update Set form.

The button is simple; it is just calling the 'GlideDialogWindow' component for the 'dialog_fix_scripts_update_set' page and passing the sys_id of Retrieved Update Set that we work in.

Next step is to create the 'dialog_fix_scripts_update_set' UI Page. Add a form with the '' tags and write some client code. Html and client code are too big to include in the post so please refer to the attached Update Set.

To run the scripts we used the system processor 'ScriptFixXMLHttpProcessor'. The necessary parameters are: sysparm_sys_id (sys_id of Fix Script), sysparm_script_name (script name), sysparm_background (should be 'false' to get results output).

We implement the 'How to Run' flag with two options: 'Asynch' and 'In Order'. The second option is used when it is necessary to run scripts in a certain order. For example, one script provides data for another. In that case the process will be cancelled if one of the scripts throws an exception.

WHAT WE GOT

As a result, we got a simple and effective solution for running Fix Scripts.

image

It saves time and provides ability to control the process from one form. There are many ways to optimize or extend the described solution. Nothing is ideal in the world so you can improve the code for your needs.

SOURCES

View original source

https://www.servicenow.com/community/developer-articles/running-fix-scripts-from-update-set/ta-p/2330472