Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION

Distribute NPrinting reports after reloading a Qlik App

No ratings
cancel
Showing results for 
Search instead for 
Did you mean: 
JonnyPoole
Former Employee
Former Employee

Distribute NPrinting reports after reloading a Qlik App

Last Update:

Jul 14, 2021 12:20:23 PM

Updated By:

Frank_S

Created date:

Mar 8, 2018 10:52:50 AM

Attachments

***UPDATED 06/30/2021

To resolve rest connector related issues visit:

 

**UPDATED 10/16/2020

Revised Sense Sample to include updated cookie parsing and proper error handling

Added sample to trigger an NPrinting User Import Task from Qlik Sense

****

One of the most common questions is how can i distribute my NPrinting reports to occur automatically as soon as my Qlik app is done reloading ?

THis is possible in both Qlik Sense and with QlikView using the NPrinting API. Moreover, you can invoke the API through the the Qlik load script Qlik REST Connector v1.3+.  What this means is that you can schedule and/or chain your NPrinting report distributions using the Qlik Sense scheduler or the QlikView publisher to better integrate the operations across the platform

.The sample included herein draws on the great document published by gianluca perrin on Qlik Community here:   https://community.qlik.com/thread/292037

Benefits

  1. Common Scheduler

    Currently NPrinting and QLik (Sense or View) have separate schedulers.

    If you reload a Qlik application daily at 1:00AM and want to send the NPrinting reports directly after a successful reload, you must schedule them separately for times that you believe  will not intefere with each other.   Its better to have a100% chained solution however whereby reports are only distribute upon successful reload of the Qlik app.


  2. Error handling

 

     Should the NPrinting task, publisher has a built in solution to notify administrators. Qlik Sense also has 3rd party solutions to do the same.

 

 

Restrictions

 

       You need to have v1.3 of the Qlik REST Connector. Its available as of  Feb 2018.

 

Sample

 

       Connection setup


       You will need to create two REST Connector connections to the NPrinting API.  One that uses a default HTTP method of "GET" , the other will use "POST" as the default method.

        Please reference pages 8-9 of the document  https://community.qlik.com/thread/292037  to create the two connections.

 

Image 1 Get Rest Connection.png

                    

Image 2 Post Rest Connection.png

                      

      App Setup

               1. Import the attached application and open the script in the Data Load Editor

               2. Modify the SETUP tab to reflect your

 

                    i. on lines 25/26  update the names of the two REST Connections that you create using the steps in 'Connection Setup' above.

                    ii. on line 30 , if NPrinting is configured to use https (it is by default) leave this setting to 'Yes' .  If you reconfigured it to use http , set to 'No'

                    iii.   On line 31 ,  set the NPrinting server and endpoint  (host + port)

                    iv:   Line 35 is the name of the NPrinting Publish Task that you want to execute

                    v:   Line 37 and 38 is an enhancement to have Qlik check the NPrinting task executions for errors, or , if it runs too long, to abort it and report a failure .

Image 3 Variables.png

                              

                  3.  (optional)  You can also Import the following application into Qlik Sense to send an administrative alert. THis is not necessary with QV Publisher as it has an in-built feature to notify administrators when a publish task fails.

                      

                 4. Open the imported app in the data load editor and update the 'setup' section

                     i.   on lines 21/22  update the names of the two REST Connections that you create using the steps in 'Connection Setup' above.

                    ii.   on line 26 , if NPrinting is configured to use https (it is by default) leave this setting to 'Yes' .  If you reconfigured it to use http , set to 'No'

                    iii.   On line 37 ,  set the NPrinting server and endpoint  (host + port)

                    iv:   Line 32 is the name of the NPrinting Publish Task that will alert an administrator about a report failure

              

                     (note that i've toyed with using the Notification Web Connector to send an administrative email alert in the event of a full blown NPrinting outage.  This sample is a little simpler)

 

Image 4 Variables.png

                       

       Task setup

                In Qlik Sense QMC under tasks i've setup 3 tasks .

 

                Task #1 - reloads  a Qlik App

                Task #2 - Distributes reports in an NPrinting Publish task     (this is chained to execute 'on success' of Task #1)

                 Task #3 - Send an Administrator alert   (this is chained to execute 'on failure' of Task #2)

               Image 5 Task setup.png

 

QLIKVIEW

 

            The QLikVIew solution has all the same benefits as the Qlik Sense solution with a couple more benefits.

            Additional benefits:

             - you can pass the vTask  name from the publisher task to make for greater re-usability of the load script for chaining multiple tasks

             - Publisher has a built in admin notification feature. SHould the NP task fail, the publisher task will also fail and an admin notification will be sent  (you can do that with qlik sense but need to use a 3rd party qlik sense task notification solution, or use the load script to call an administrative task to send a notification. The latter can be done with NPrinting or with the Qlik Web Notification Connector.

 

Load script

 


The QlikView load script has a login ,  get task ID (lookup using task name),  post task execution, and a task execution check  tab.    The task execution check tab will monitor the NP task execution on an interval with a configurable timeout.  Should the NP task throw a warning or error, it errors out the publisher task.  Should the NP task exceed the timeout, it kills the NP task and errors out the publisher task.

 

You will need to update the NPServer, Task and timeout settings in the CONFIG tab.  Again use the REST Connector 1.3 and i suggest testing with QV desktop first .  The REST Connector must be manually installed on QV desktop and on the publisher machine to work.

 

Image 6 Load Script.png

 

New cookie parsing:

//Set Cookie header

let vCookieRaw = peek( 'Set-Cookie',0,'_response_header');

if vSSL='False' then
let vCookie= subfield(subfield('$(vCookieRaw)','Path=/,',3),';',1);
else
// let vCookie = TextBetween('$(vCookieRaw)','Secure,','Path=/',2);

Let vCookie = TextBetween('$(vCookieRaw)','SameSite=None,','; Path=/',3);
end if

 

Related information:

Labels (2)
Comments
tanvi_madan1
Partner - Contributor III
Partner - Contributor III
You can write a code with for loop block. To trigger task one after another.

Thanks,
Tanvi
0 Likes
Bernardvanecek
Contributor
Contributor

Hi Tanvi, 

thanks for advice, I am really a noob in this so I'm not really sure how can I do this?
Can you please help me with this?

B.

0 Likes
Anilb1603
Contributor III
Contributor III

Hi All,

I have downloaded this QS sample app and defined all the connections and variables and it has successfully triggered a  Nprinting publish task in but unfortunately I didn't any find any option here to send out a email notification to Administrators when the task fails. Can please someone point me to the correct part of script where the task notification part is configured..

Thanks,

Anil

0 Likes
JonnyPoole
Former Employee
Former Employee

Using this technique, there is both a qlik sense reload task and an nprinting task execution.  

If you have a solution to do an email notification when a qlik sense reload task fails, it will kick in here.  That's because in the script i put a polling mechanism to report back the status of the NP execution and to cause a reload failure in the reload script if the np task does not finish with a 'success' status. 

You could use the feature below on nprinting if the NP task fails too. 

 

 

community.png

0 Likes
Anilb1603
Contributor III
Contributor III

Thanks @JonnyPoole ,

We don't have any email notification in qlik sense.

We have seen this feature in nprinting and its useful but we are looking for  task level email configuration instead one generic email get notified for all the tasks in nprinting. We want to notify the task owner/developer instead of admin.

JonnyPoole
Former Employee
Former Employee

Got it.  Yes I've heard that from other customers too.  It would be nice to variablize this setting but we can't today. Before the feature was available i used to tell customers they could: 

 

1.   Call ANOTHER NPrinting task execution that just emails something to an admin

2.    Send a very basic email using the SMTP Connector (its a web connector) directly through the load script. 

https://help.qlik.com/en-US/connectors/Subsystems/Web_Connectors_help/Content/Connectors_QWC/Data-So...

Have you used web connectors before ? They are handy for some little admin tasks too. 

 

miguelbraga
Partner - Specialist III
Partner - Specialist III
Hi there,
 
I've already used part of your scritpt to create a Qlik Sense app that triggers a task in Qlik NPrinting in my personal own Virtual Machine and changed it a bit to work in the protocol method HTTP. In my VM it worked so far so good and I could easly used some jobs existed in the code.
 
The problem here is that when I've tried to use in a customer's environment which are a little bit different that all the customer's I've been dealing with. This specific customer has the default port for the Web Console as 443 rather that the pre-deafult one 4993. In this case I can't get the App Ids, nor the Connections Ids, nor the Tasks Ids and so I can't make this work.
 
Does this script works when the pre-default port 4993 to the Web Console is changed?
 
Thank you in advance.
 
Kind regards,
Miguel Braga
JonnyPoole
Former Employee
Former Employee

hi yes that should be fine.   Update your GET and POST connections and replace '4993' with '443'. 

Also on line 30 of the Config section of the script , change the following line to use 443 instead of 4993

Here is line 30 in the QVF in this article. You probably already changed the servername so just change the port.

let vNPrintingServer='<EnterServerName>:4993';

You can also search the script (all sections) from within the data load editor for '4993' to see if there were any other places that were missed. 

 

-jonny

0 Likes
miguelbraga
Partner - Specialist III
Partner - Specialist III
Hi there,
 
I must update my earlier post by confirming that I've changed a little bit of this code so that this code works in any port defined in the port for the NPrinting Web Console.  I have a fully functional code using the aforemention code in this article.
 
Special thanks to the developer who managed to create this code and share it with the Qlik Community.
 
Kind regards,
Miguel Braga
0 Likes
digimech
Partner - Contributor III
Partner - Contributor III

Hi @JonnyPoole 

I'm using Qlik Sense Nov 2021 Patch 2 and I'm having issue with the task. I see below error.

anjit_tiwari_0-1645808497155.png

I followed the https://community.qlik.com/t5/Knowledge/Qlik-Sense-June-2020-connecting-to-NPrinting-getting-quot-HT...and made change to the cookies setting as suggested on articles. but still have the same error.

 

 

0 Likes
Contributors
Version history
Last update:
‎2021-07-14 12:20 PM
Updated by: