Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
katwijck
Contributor III
Contributor III

IF.. Then.. Else not working as intended with ScriptError

Hello everyone,

I have been searching the forums for a solution or explanation however until now i am not able to find either

The following is the situation:

I have a script in which a connection is made via ODBC to a SQL source.

However i would like QlikView to load existing data from QVD's if the ODBC connection cannot be established (via the ScriptError) but i do not seem to get this working.

I have tried the same idea with setting up a variable which should set the value to "Good" if the THEN bit is processed and "Bad" when the ELSE bit is processed but i only seem to getting the ELSE bit being processed.

SET Errormode=0;

ODBC CONNECT TO Test;
Let vScriptError = ScriptError;
Let vScriptErrorDetails = ScriptErrorDetails;

If ScriptError=1 THEN

SET vTest='Good';

ELSE

SET vTest='Bad';

END IF

I have tried multiple ScriptError codes and >0 but nothing seems to trigger the THEN bit.

With kind regards,

Martin van der Bent

1 Solution

Accepted Solutions
maxgro
MVP
MVP

SET Errormode=0;

ODBC CONNECT TO Test;

Let vScriptError = ScriptError;

Let vScriptErrorDetails = ScriptErrorDetails;


If vScriptError=0 THEN

       SET vTest='Good';

ELSE

       SET vTest='Bad';

END IF

TRACE $(vTest);

View solution in original post

4 Replies
eespiritu
Creator
Creator

Hi Martin,

Maybe you are using a wrong statement for your if condition. The ScriptError statement gives you a string, not a numeric value. Try this:

SET Errormode=0;

ODBC CONNECT TO Test;

//Let vScriptError = ScriptError;

Let vScriptError = ScriptErrorCount;

Let vScriptErrorDetails = ScriptErrorDetails;

If '$(vScriptError)'=1 THEN

SET vTest='Good';

ELSE

SET vTest='Bad';

END IF

Regards,

Enrique.

maxgro
MVP
MVP

SET Errormode=0;

ODBC CONNECT TO Test;

Let vScriptError = ScriptError;

Let vScriptErrorDetails = ScriptErrorDetails;


If vScriptError=0 THEN

       SET vTest='Good';

ELSE

       SET vTest='Bad';

END IF

TRACE $(vTest);

katwijck
Contributor III
Contributor III
Author

Hi Enrique,

I have validated this approach and it seems to do the trick!

Thanks for the help.

With kind regards,

Martin van der Bent

katwijck
Contributor III
Contributor III
Author

Hi Massimo,

I see the mistakes I have made in my script, thanks for pointing it out, works like a charm!

With kind regards,

Martin van der Bent