Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
MynhardtBurger
Contributor III
Contributor III

Unable to store the content of error handling variables

I am unable to store the value of the script error variables in a table.

https://help.qlik.com/en-US/qlikview/November2017/Subsystems/Client/Content/Scripting/ErrorVariables...

The only error variables I am able to store in a table is '$(ScriptErrorCount)' and '$(#ScriptError)'. All the other variables return as null. Why is this?

The structure of my code, which runs in a for loop, is this:

Set ErrorMode=1;

//Attempt to load non-existing file
[Budget Raw]: LOAD [Customer Number], [Item Code], [SP 01], [SP 02], [SP 03], [SP 04], [SP 05], [SP 06], [SP 07], [SP 08], [SP 09], [SP 10], [SP 11], [SP 12], [RM 01], [RM 02], [RM 03], [RM 04], [RM 05], [RM 06], [RM 07], [RM 08], [RM 09], [RM 10], [RM 11], [RM 12], [Qty 01], [Qty 02], [Qty 03], [Qty 04], [Qty 05], [Qty 06], [Qty 07], [Qty 08], [Qty 09], [Qty 10], [Qty 11], [Qty 12], [Days 01], [Days 02], [Days 03], [Days 04], [Days 05], [Days 06], [Days 07], [Days 08], [Days 09], [Days 10], [Days 11], [Days 12] FROM '$(non-existingFile)' (ooxml, embedded labels, header is 1 lines, table is [Sales Budget]); //Save error details to preexisting [Load Results] table
Concatenate ([Load Results]) LOAD '$(t)' as [File Number], //for loop counter '$(ScriptErrorCount)' as [Error Count], '$(#ScriptError)' as [Error ID], '$(ScriptError)' as [Error Description], '$(ScriptErrorDetails)' as [Error Detail], '$(ScriptErrorList)' as [Error List] Autogenerate(1);

 

I expected the error variables to contain something about file not found, as it is shown when inspecting those variables while running the script in debug mode.

1 Solution

Accepted Solutions
MynhardtBurger
Contributor III
Contributor III
Author

I solved my problem.

Qlik resets the contents of the ScriptErrorCount , ScriptError  and ScriptErrorDetails which originated from the previous script statement as soon as a new statement is executed. So you must record the contents of the system ScriptErrorCount, ScriptError and ScriptErrorDetails in a variable right after the relevant script statement. Even a LET statement will result in those system variables being cleared.

My solution was to record the contents of all the script error system variables in a deliminated string immediately after the relevant script statement which might throw an error:

Let vScriptErrors = ScriptErrorCount & '|' & num(ScriptError) & '|' & ScriptError & '|' & ScriptErrorDetails & '|' & ScriptErrorList;

Then use the SUBFIELD function to extract the contents of each script error variable:

//Save error details to preexisting [Load Results] table
Concatenate ([Load Results])
LOAD
        '$(t)' as [File Number], //for loop counter variable
	SubField('$(vScriptErrors)','|',1) as [Error Count],
	SubField('$(vScriptErrors)','|',2) as [Error Code],
	SubField('$(vScriptErrors)','|',3) as [Error Description],
	SubField('$(vScriptErrors)','|',4) as [Error Details],
    	SubField('$(vScriptErrors)','|',5) as [Error List]
Autogenerate(1);

 

I found that the Qlik help file is incomplete in describing the operation of these variables:

  • ScriptErrorDetails variable is not listed in the help file
  • The fact that all script statements, including LET, will reset the contents of ScriptErrorCount , ScriptError and ScriptErrorDetails variables forcing you to record their contents in a single LET statement if your are interested in them

https://help.qlik.com/en-US/qlikview/November2018/Subsystems/Client/Content/QV_QlikView/Scripting/Er...

View solution in original post

1 Reply
MynhardtBurger
Contributor III
Contributor III
Author

I solved my problem.

Qlik resets the contents of the ScriptErrorCount , ScriptError  and ScriptErrorDetails which originated from the previous script statement as soon as a new statement is executed. So you must record the contents of the system ScriptErrorCount, ScriptError and ScriptErrorDetails in a variable right after the relevant script statement. Even a LET statement will result in those system variables being cleared.

My solution was to record the contents of all the script error system variables in a deliminated string immediately after the relevant script statement which might throw an error:

Let vScriptErrors = ScriptErrorCount & '|' & num(ScriptError) & '|' & ScriptError & '|' & ScriptErrorDetails & '|' & ScriptErrorList;

Then use the SUBFIELD function to extract the contents of each script error variable:

//Save error details to preexisting [Load Results] table
Concatenate ([Load Results])
LOAD
        '$(t)' as [File Number], //for loop counter variable
	SubField('$(vScriptErrors)','|',1) as [Error Count],
	SubField('$(vScriptErrors)','|',2) as [Error Code],
	SubField('$(vScriptErrors)','|',3) as [Error Description],
	SubField('$(vScriptErrors)','|',4) as [Error Details],
    	SubField('$(vScriptErrors)','|',5) as [Error List]
Autogenerate(1);

 

I found that the Qlik help file is incomplete in describing the operation of these variables:

  • ScriptErrorDetails variable is not listed in the help file
  • The fact that all script statements, including LET, will reset the contents of ScriptErrorCount , ScriptError and ScriptErrorDetails variables forcing you to record their contents in a single LET statement if your are interested in them

https://help.qlik.com/en-US/qlikview/November2018/Subsystems/Client/Content/QV_QlikView/Scripting/Er...