Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

katwijck
New Contributor II

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
MVP
MVP

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

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);

4 Replies
eespiritu
Contributor

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

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.

MVP
MVP

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

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
New Contributor II

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

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
New Contributor II

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

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

Community Browser