Today I am going to blog about Error Variables and how they can be used in an app.  Error variables are available in Qlik Sense and QlikView to:


  1. Determine what actions should be taken if an error occurs during script execution
  2. Provide information about error(s) that occur during script execution


The four error variables I will review in this blog are:


  1. ErrorMode
  2. ScriptError
  3. ScriptErrorCount
  4. ScriptErrorList


Of the 4 error variables, ErrorMode is the only variable that is set by the user.  This variable determines what should happen if an error occurs during script execution.  This variable is set in the script like this:


ErrorMode can take one of three values: 0, 1 or 2.  By default, ErrorMode is set to 1.  This means that if there is an error during script execution, the script will stop and prompt the user for an action.  When ErrorMode is set to 0, the error will be ignored and the script execution will continue.  When ErrorMode is set to 2, the script will fail and stop.  The ErrorMode variable should be set at the beginning of the script or before a section of the script where you know there may be errors that you would like to handle.  Once the ErrorMode is set, it will remain the same unless the ErrorMode variable is reset/changed later in the script.  For instance, you may opt to set the ErrorMode variable to 0 if there is an area in your script that may throw errors that you would like to ignore (not stop script execution).  In this case, you may need to set ErrorMode back to 1 if you want to be notified of other errors later in the script.


Let’s see how the error messages are presented if I run the simple script below to load a group of Excel files that start with “Book.”  Note, that all the files loaded do not include the “Monthly Sales” field.

Load script.png

If I precede this script with Set ErrorMode = 0, this is what I see when the script is complete.


Notice that the script finished executing even though there was an error.  Now let’s see what happens if we keep the default (ErrorMode = 1) or set ErrorMode = 2.


Here the script execution stopped at the error and did not complete providing the option to Close, correct the script and reload again.


Unlike the ErrorMode variable, the ScriptError, ScriptErrorCount and ScriptErrorList variables are output from Qlik Sense or QlikView that provide information about the error that was encountered when the script was executing.  The ScriptError variable will return an error code.  A list of the error codes and their descriptions can be found here in Qlik Sense Help.  ScriptErrorCount returns the number of statements that caused an error during script execution.  Lastly, the ScriptErrorList variable returns a list of the errors encountered during script execution.  If there is more than one error, they are separated by a line feed.  These error variables can be accessed in the script or via the UI.  In the script, you can simply refer to the ScriptError variable to find its’ value.  For example, in the script below, I can check for the error code 8 (“File not found”) to determine if the file being loaded was missing.


Error variables can also be access in the UI via the Text & image object.  In the Text & image object measure, simply enter an equal sign and the name of the variable like this:


To return something like this:


Error variables are useful and easy to use.  I find ErrorMode = 0 the one I use the most when I know there is a chance that the script may throw an error that is ok to ignore.  It is also useful if you need to control the path of the script’s execution based on an error.  You can learn more about error variables in Qlik Sense Help.