Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
josemaria_cabre
Contributor III
Contributor III

Error handling in script

Hi everyone!

Let's imagine we have this load statement that we execute e.g. once a week:

[data]:
LOAD
 [Reservation id],
 [ID member],
 [Code MA],
 [Registration date],
 FROM [lib://Folder/file.csv]
(txt, codepage is 28591, embedded labels, delimiter is '\t', msq)

But .csv coding  from file.csv might change from one week to another, and instead of:

(txt, codepage is 28591, embedded labels, delimiter is '\t', msq)

This week's coding will be:

(txt, utf8, embedded labels, delimiter is ';', msq);

 So we'll get a 'Field xxxx not found' error when executing our script.

Is there any way to load [data] table again using an alternative .csv coding when such an error occurs?

I tried using  the 'ScriptError' function with no success on my script. Could anyone help with this issue? 

Thanks in advance for your help,
Jose.

 

1 Solution

Accepted Solutions
dplr-rn
Partner - Master III
Partner - Master III

Can you share the error handling script you used?

Hope you set the errormode to 0

below has worked for me in past

set ErrorMode=0;

load * from abc.csv;

if ’$(ScriptError)’=’File Not Found’ then  // or if ScriptError=8 then

//execute the error handling statements

end if

in your case script error should 11 ofcourse

View solution in original post

6 Replies
dplr-rn
Partner - Master III
Partner - Master III

Can you share the error handling script you used?

Hope you set the errormode to 0

below has worked for me in past

set ErrorMode=0;

load * from abc.csv;

if ’$(ScriptError)’=’File Not Found’ then  // or if ScriptError=8 then

//execute the error handling statements

end if

in your case script error should 11 ofcourse

josemaria_cabre
Contributor III
Contributor III
Author

I tried this:

set ErrorMode=0;

[data]:
LOAD
 [Reservation id],
 [ID member],
 [Code MA],
 [Registration date],
 [Agent name]
FROM [lib://Folder/file.csv]
(txt, utf8, embedded labels, delimiter is ';', msq);

if ScriptError=11 then


[data]:
LOAD
 [Reservation id],
 [ID member],
 [Code MA],
 [Registration date],
 [Agent name]
FROM [lib://Folder/file.csv]
(txt, codepage is 28591, embedded labels, delimiter is '\t', msq);

end if

dplr-rn
Partner - Master III
Partner - Master III

Hm.. weird

I just tried simulating the issue with a wrong column name and it worked.

Try debugging and check exact text of the ScriptError. and/or try use the text comparison

maybe its 12 not 11

below from help page

11Field not found
12File has wrong format
josemaria_cabre
Contributor III
Contributor III
Author

Hi!

You were right. Script executes and it loads data  from file.csv, but still a message "errors were found during execution" is shown in data load progress window.

Is there any way to avoid this?

error.png

 

 

jaygarcia
Contributor III
Contributor III

Hola Jose,

As far as know there's no way to avoid this error message. What I do is to write a message in a TRACE saying that it's not an error and the message should be ignored.

Hope this helps.

Jay

josemaria_cabre
Contributor III
Contributor III
Author

Good idea! Thanks everyone for your help.

Jose