Skip to main content
Announcements
Accelerate Your Success: Fuel your data and AI journey with the right services, delivered by our experts. Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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.

 

8 Replies
Peter_Cammaert
Partner - Champion III
Partner - Champion III

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
Partner - Specialist III
Partner - Specialist III

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;

Anonymous
Not applicable
Author

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.

pjaredchurch
Contributor III
Contributor III

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

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;
je48746stijn
Contributor III
Contributor III

Hi Yann,

when I run this code, I get the message : "Connection 'Repository' not found".  Do you have an idea what could be wrong?  Thanks in advance.

yann_courtet
Partner - Contributor II
Partner - Contributor II

You should create a connection to your  repository database first.

hewemel1
Partner - Contributor II
Partner - Contributor II

Thanks for this solution. It works like a charm.

Does it bring a security issue? And if yes, how could this be handled?

(In my environment, many apps with several developers would profit from using this mechanism in their scripts: Based on the stream, folder connections for include commands and for QVD data read/write could be switched when an app goes from a DEV stream to a PROD stream. But then, the qliksense service user need to have access to the repository db connection. Using this, any developer can fully read the repository, after its app has been published... We have just started the migration from QlikView to Qlik Sense. So, my knowledge is still very limited. Please excuse if my question does not make sense...)