Qlik Community

Qlik Sense Data Connectivity

Discussion board where members can learn more about Qlik Sense Data Connectivity.

iahamedabdullah
New Contributor II

Dynamically Changing "Data Connections" based on "Streams"

Hi Everyone,

Is there an option to Dynamically change data source in Qlik sense? 

For example, I have three streams(DEV, UAT, PROD ) and I need to connect to three different data sources(DEV, UAT, PROD),

Is there a way like I should not change the connection string but it should pick up the data source dynamically when I deploy in respective streams(DEV, UAT, PROD)? Can you please reply. Thanks in advance!

Thank you,

Ahamed

4 Replies
chadwatson
New Contributor III

Re: Dynamically Changing "Data Connections" based on "Streams"

Hi Ahamed, did you figure out a way to do this? I am am looking to do the same thing.

demlet123
New Contributor III

Re: Dynamically Changing "Data Connections" based on "Streams"

Hi Ahamed,

I personally haven't tried anything regarding this, but the first thing comes to mind is an IF ELSE statement using a source-path that would be included in the script. Then when you "deploy" to a stream the files would change locations/paths. Therefore the script would automatically account for it.

A few functions that come to mind to get a path...

-GetFolderPath

-DirList

-FileList

-DocumentName

-DocumentPath

-DocumentTitle

Please let me know if you end up finding a viable solution. If I end up finding time to test this I will reply back.

-Derek

iahamedabdullah
New Contributor II

Re: Dynamically Changing "Data Connections" based on "Streams"

Hi Derek,

If the Source is file system, then we can apply IF ELSE and use the functions which you mentioned.

-GetFolderPath

-DirList

-FileList

-DocumentName

-DocumentPath

-DocumentTitle

what if we are using OLEDB conection to connect to SQL server?

the ideal solution for this would be, We need some qlik function to identify the stream Name, that way we can apply IF ELSE and swap the connections.

thanks.

kaanerisen
Contributor III

Re: Dynamically Changing "Data Connections" based on "Streams"

Hi,

First of all you need to create 4 data connection. DEV, UAT, PROD and POSTGRE_QSR(qlik sense database). We need QSR connection to fetch the stream name of the app.


Untitled.png


let appId = DocumentName();

LIB CONNECT TO 'POSTGRE_QSR';

Temp_App_Stream:

load

ID as AppID,

    Name as StreamName;

SELECT app."ID",str."Name"

FROM public."Apps" app

left join public."Streams" str on app."Stream_ID"=str."ID"

where app."ID"='$(appId)';      

   

let DataSourceName = peek('StreamName');

DROP TABLE Temp_App_Stream;

LIB CONNECT TO '$(DataSourceName)';

If you get the logic, you are able to modify this script based on your needs.

Hope it helps.

Community Browser