Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

OmarBenSalem
Esteemed Contributor

Control/handle connection errors

Hi folks,

The title's question is maybe not that clear, but I'll try to explain what I'm willing to achieve:

Situation:

I'm using Qlik REST Connector to retrieve some data.

Problem:

The web services team have developed 2 web services that have the same data.

WS1: URL1

WS2 : URL2


This approach of building the same WS in 2 different servers (dev and int) was due to some deployment issues..

I mean sometimes, when I try to connect to URL1 , I can't access to it, so I immediately change my Qlik Rest connector URL to URL2..

(all of this is temporary till the building of a stable WS in the prd environment)

So, for test reasons, while I'm on my qlik sense DESKTOP, I can handle this manually..

I reload data = > have errors => Solution: change the URL

BUT, I can't do this if I deploy my application in the qlik sense ENTREPRISE.

Solution I'm seeking for:

So, basically, what I'm looking to do/ask for:

Is there wa way to control/handle how Qlik responds to connection errors?

I mean, instead of interrupting the data reloading process; I want to build sthing like this:

if CONNECTION to the WS through URL1 fails => CONNECT to the WS using URL2 without interrupting the data loading process..

Can this be done?

If yes, how?

I'm aware of the ErrorMode thing, but I'm not sure how to use it in my case.

Any hint/help?

1 Solution

Accepted Solutions

Re: Control/handle connection errors

Something like this:

SET ErrorMode=0;

LOAD stuff FROM URL1;

if ScriptError>0 then

     // an error occured so try URL2

     LOAD stuff FROM URL2;

end if

SET ErrorMode=1;


talk is cheap, supply exceeds demand
10 Replies
OmarBenSalem
Esteemed Contributor

Re: Control/handle connection errors

Re: Control/handle connection errors

Something like this:

SET ErrorMode=0;

LOAD stuff FROM URL1;

if ScriptError>0 then

     // an error occured so try URL2

     LOAD stuff FROM URL2;

end if

SET ErrorMode=1;


talk is cheap, supply exceeds demand
OmarBenSalem
Esteemed Contributor

Re: Control/handle connection errors

I'll try and let u know ! Thanks

OmarBenSalem
Esteemed Contributor

Re: Control/handle connection errors

I was trying to do sthing like this:

let vUrlMailDev= url1;

let vUrlMailInt= url2;

SET ErrorMode=0;

LIB CONNECT TO 'Post Today (send email)';

RestConnectorMasterTable:

SQL SELECT

"result"

FROM JSON (wrap on) "root" WITH CONNECTION(

BODY "$(vRequestBody2)" URL "$(vUrlMailInt)"

);

[root]:

LOAD [result] AS [result]

RESIDENT RestConnectorMasterTable;

DROP TABLE RestConnectorMasterTable;

if ScriptError>0 then

LIB CONNECT TO 'Post Today (send email)';

RestConnectorMasterTable:

SQL SELECT

"result"

FROM JSON (wrap on) "root" WITH CONNECTION(

BODY "$(vRequestBody2)" URL "$(vUrlMailDev)"

);

[root]:

LOAD [result] AS [result]

RESIDENT RestConnectorMasterTable;

DROP TABLE RestConnectorMasterTable;

end if

SET ErrorMode=1;

Do u know how to combine with connection body with with connection url?

I've used both of these seperately, but when I try to combine both, i can't achieve it (syntax thing)

Thanks

OmarBenSalem
Esteemed Contributor

Re: Control/handle connection errors

just add a comma between the 2 would work.

WITH CONNECTION(

BODY "$(vRequestBody2)" , URL "$(vUrlMailDev)"

);

OmarBenSalem
Esteemed Contributor

Re: Control/handle connection errors

does this work? (syntax of many if..)

SET ErrorMode=0;

LIB CONNECT TO 'Post Today (send email)';

RestConnectorMasterTable:

SQL SELECT

"result"

FROM JSON (wrap on) "root" WITH CONNECTION(

BODY "$(vRequestBody2)", URL "$(vUrlMailInt)"

);

[root]:

LOAD [result] AS [result]

RESIDENT RestConnectorMasterTable;

DROP TABLE RestConnectorMasterTable;

if ScriptError>0 then

LIB CONNECT TO 'Post Today (send email)';

RestConnectorMasterTable:

SQL SELECT

"result"

FROM JSON (wrap on) "root" WITH CONNECTION(

BODY "$(vRequestBody2)", URL "$(vUrlMailInt)"

);

[root]:

LOAD [result] AS [result]

RESIDENT RestConnectorMasterTable;

DROP TABLE RestConnectorMasterTable;

else

if ScriptError>0 then

LIB CONNECT TO 'Post Today (send email)';

RestConnectorMasterTable:

SQL SELECT

"result"

FROM JSON (wrap on) "root" WITH CONNECTION(

BODY "$(vRequestBody2)", URL "$(vUrlMailInt)"

);

[root]:

LOAD [result] AS [result]

RESIDENT RestConnectorMasterTable;

DROP TABLE RestConnectorMasterTable;

end if

end if

SET ErrorMode=1;

Re: Control/handle connection errors

No, that won't work. You use the same test in both if statements. So the first if will execute if ScriptError > 0 and the second if never will because the first if already took care of it.


talk is cheap, supply exceeds demand
OmarBenSalem
Esteemed Contributor

Re: Control/handle connection errors

what I'm trying to do, is trying to perform the same connection with the same URL more than once; let's say 3 or 4 times (or as long as it takes) till the connection is done without throughing errors.

Due to issues in the server where the ws is deployed, sometimes it takes 3 or 4 tries till the connection is finally made..

Hope my aim is clear and that u would have a solution to such a situation?

Re: Control/handle connection errors

Have a look at this video: Qlik #033: If at first you don't succeed, Error Trap! - YouTube. You should be able to appy the same technique in Qlik Sense.


talk is cheap, supply exceeds demand
Community Browser