Qlik Community

Qlik Design Blog

All about product and Qlik solutions: scripting, data modeling, visual design, extensions, best practices, etc.

Read about the latest Qlik Community enhancements on the Community News blog!

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.





Speaking from experience, be very careful when it comes to using ErrorMode = 0 without error handling. Sometimes one issue during a reload can cause a chain reaction that will either turn the entire model into gibberish, or worse, cause the reload to hit 100% resources and clog the server. Make sure you are placing this in parts of the script where you can actually safely continue without the specific loads involved.

In particular, you should be careful / avoid using ErrorMode = 0 without error handling in the following situations:

  • Data is consolidated from multiple sources and one of them could potentially be offline / unavailable. In this situation it's usually be better to have day-old data rather than partial data.
  • Anywhere involving a JOIN/KEEP chain. In this situation, you can potentially set up a join on partial fields or on too many fields, or worst of all - on no fields at all, creating a Cartesian join/keep.
  • Any load which is significant to the end result and it is not immediately obvious to the user that the information is missing. For example, if you have a load with some manual adjustments to a Profit and Loss statements and this fails, your users may not be able to tell that it failed and the P&L is inaccurate.
  • Any situation in which you might be creating mismatched files - for example, one QVD will be up-to-date and another will not as a result of the failed load. Sometimes this isn't an issue, but in other cases it can cause significant data problems.

In all of these situations, I would probably avoid using ErrorMode = 0 unless you've built proper error handling into your script using the other load variables. Being out of date by a day is likely to be better than displaying incorrect results or clogging your server.


Good post!