This is going to be a short post, but I put a lot of effort and time to prepare it. It will circle around Qlik NPrinting API and already well described here by Gianluca method of using Qlik RESTfull connector to send requests to NPrinting API from QlikView or Qlik Sense script. Please read his document well and also go through his post and questions from users to troubleshoot connection issues, authentication etc.
So, I have spent few weeks trying to go through NPrinting API methods and put as many of them as possible in Qlik script subroutines. Attached here is NPrinting.qvs file which contains ready to use Subroutines.
This QVS files contains 3 sections:
- SETUP & SETTINGS – this is configuration section which you need to configure in order to get everything working. In setup section I have provided configurations of GET and POST RESTfull connections. SETTINGS section uses variable to configure hostnames of Qlik Sense/QlikView, Qlik NPrinting, Library/Path connections etc.
- TASK section contains individual methods
- JOB section contains samples of jobs which you can easily create using procedures from TASKS
Let’s have a look at how we can use it.
We need to load NPrinting.qvs file using Include (I always use Must_Include to make sure that I do not skip any code). This will get all subroutines available for us to call. In the JOB SETS section i created job sample(s) which combine individual tasks into logical path. For example this one:
NP_JOB_Reload_N_Publish sub combines following subs:
- authenticates and captures session cookie
- gets AppId based on vNPrintingAppName parameter – this is a NPrinting app name which will be used in subsequent steps
- gets all ConnectionsId(s) with optional connection name parameter (if not specified it loops through all connections from in AppId. Reloads metadata of those connection. There is additional parameter (metadata reload timeout which allows to stop it if it runs for longer than specified time)
- Gets all Publish Tasks (based on vNPrintingTaskName) which can be:
- empty – all tasks
- comma separated: list of tasks to trigger
- task name – single task to trigger
- Triggers above mentioned task(s) and waits for them to finish publishing.
This all can be handled in QlikView or Qlik Sense using 2 lines of script code:
In line 21 I include qvs file.
In line 23 i call “job NP_JOB_Reload_N_PublishTask” to:
- go to NPrinting Application called ‘Testing’,
- check and reload all Connections in this App (note: ” in parameter string)
- if metadata reload goes longer than 10 minutes then abort (note 10 as last parameter)
- publish “testing” and “testing12” tasks.
This is just a sample of what can be done. QVS file contains Sub(s) allowing you to delete users, import users from table loaded into Qlik, create or update users groups, filters, roles. User imports are based on XLS templates from Qlik Help site, but can also come directly from any other table which will have suitable fields. This is still work in progress and the whole purpose of it is to show that you can create quite flexible tool according to your needs and you can move entire scheduling and NPrinting distribution entirely to QMC.
QVS file contains my approach, but you can use it as an inspiration to write your own script, modify mine to suite you better and explore NPrinting API more. You can see in my examples how to change POST method to PUT, PATCH or DELETE.
Depending on your needs you can create jobs directly in Qlik Script or call all required tasks independently. It is all up to you.