Qlik Community

Qlik Sense App Development

Discussion board where members can learn more about Qlik Sense App Development and Usage.

uogaz079
New Contributor II

QSense: How to get the current stream name

Hi everybody! 

Is there any function or instruction that retrive the current stream name that is running the Qsense application on the server?

 

I developed an application “DATA_Mayuda” in the hub server. The application connects to a database. Then read a table, generate a QVD, and finally drop the table. All that works well.

 

LIB CONNECT TO 'Mesa de Ayuda QA';

WorkOrder:

SQL SELECT * FROM servicedesk.workorder;

STORE WorkOrder into [lib://QlikShared/_Test\Mesa de Ayuda\QVD\workorder.qvd];

Drop Table WorkOrder;

 

Now, I need to store the QVD file according to the current stream. But I don´t know how to resolve it.

 

 

LIB CONNECT TO 'Mesa de Ayuda QA';

WorkOrder:

SQL SELECT * FROM servicedesk.workorder;

-- FunctionThatRetriveCurrentStream (vCurrentStream); ?????

If vCurrentStream = “Testing” then

       STORE WorkOrder into [lib://QlikShared/_Test\Mesa de Ayuda\QVD\workorder.qvd];

Else

        STORE WorkOrder into [lib://QlikShared/_Production\Mesa de Ayuda\QVD\workorder.qvd];

End if

Drop Table WorkOrder;

 

Thanks in advanced.

 

Ulises Yair Ogaz | Analista Técnico/Desarrollador JDE - SISTEMAS

  Laboratorios Casasco S.A.I.C.

 

5 Replies

Re: QSense: How to get the current stream name

You posted a Qlik Sense question in a forum called "QlikView App Development". Please move your question to an appropriate Qlik Sense forum by following the steps specified here: QlikCommunity Tip: How to move your discussion thread

Thanks.

felipedl
Valued Contributor III

Re: QSense: How to get the current stream name

Hi Ulises,

There's no function to get the stream of an app in the script side.

For what you want, you could do two apps differentiating between Test and Prod environment.

Would be the same code, but with different stores.

- Test env

LIB CONNECT TO 'Mesa de Ayuda QA';

WorkOrder:

SQL SELECT * FROM servicedesk.workorder;


STORE WorkOrder into [lib://QlikShared/_Test\Mesa de Ayuda\QVD\workorder.qvd];

Drop Table WorkOrder;


- Prod env

LIB CONNECT TO 'Mesa de Ayuda QA';

WorkOrder:

SQL SELECT * FROM servicedesk.workorder;


STORE WorkOrder into [lib://QlikShared/_Production\Mesa de Ayuda\QVD\workorder.qvd];

Drop Table WorkOrder;

uogaz079
New Contributor II

Re: QSense: How to get the current stream name

Thanks Peter. I've moved it to Qlik Sense - App Development & Usage

Ulises Yair Ogaz | Analista Técnico/Desarrollador JDE - SISTEMAS

Laboratorios Casasco S.A.I.C.

jaredchurch
New Contributor II

Re: QSense: How to get the current stream name

You can do this using the Qlik monitoring connector:

Here is the function I've done this morning (based on the load script in the Operations Monitoring app) to do exactly the same issue you're looking at.

The function is based on the load script from the Operations Monitoring App:

https://help.qlik.com/en-US/sense/June2018/Subsystems/Monitoring/Content/OperationsMonitor/Operation...

You pass the ObjectID of the app you care about (you can get that using function: DocumentName())  and when the function completes the global variable 'vReturn' will hold either the Stream name or 'Unpublished'.

SUB fGetAppStream(id)

 

  LIB CONNECT TO 'monitor_apps_REST_app';

 

  RestConnectorMasterTable:

  SQL SELECT

      "id" AS "id_u4",

      "name" AS "name_u3",

      "published",

      "__KEY_root",

      (SELECT

          "name" AS "name_u2",

          "__FK_stream"

      FROM "stream" FK "__FK_stream")

  FROM JSON (wrap on) "root" PK "__KEY_root";

 

//   LET NumRows_monitor_apps_REST_app = NoOfRows('RestConnectorMasterTable');

 

  map_stream:

  Mapping LOAD

      [__FK_stream] AS [__KEY_root],

      [name_u2] AS Stream

  RESIDENT RestConnectorMasterTable

  WHERE NOT IsNull([__FK_stream]);

 

  App_Stream:

  LOAD

      [id_u4] AS ObjectId,

      name_u3 as [App Name],

      ApplyMap('map_stream',__KEY_root,'Unpublished') as [App_Stream]

  RESIDENT RestConnectorMasterTable

  WHERE NOT IsNull([__KEY_root])

and id_u4='$(id)';

;


  DROP TABLE RestConnectorMasterTable;


if NoOfRows(App_Stream) <> 1 then

trace ERROR;

        set vReturn='Unpublished';

    else

let vReturn = peek('App_Stream','0','App_Stream');

    end if;



  drop table App_Stream;

ENDSUB

yann_courtet
New Contributor

Re: QSense: How to get the current stream name

This should be simpler, and should always work based on database integrity.

// Get The Stream Name or Unpublished 
let vDoc = DocumentName();

LIB CONNECT TO 'Repository';
 
APPS:
LOAD ID as App_ID, Stream_ID;
SQL SELECT "ID", "Stream_ID" FROM "QSR"."public"."Apps" WHERE "ID" = '$(vDoc)';

LEFT JOIN(APPS)
LOAD ID as Stream_ID, Name as Stream_Name;
SQL SELECT "ID", "Name" FROM "QSR"."public"."Streams";

let vStream = peek('Stream_Name',0,'APPS');

If IsNull(vStream) then 
	let vStream = 'Unpublished';
end if;

drop table APPS;
Community Browser