Trigger app reload from Qlik Script. SaaS Task chaining. Continuous reload.

Posted by

This post describes how to use Qlik APIs to trigger apps reload in Qlik SaaS, from Qlik script. This allows additional felxibility, simplier task chaining and new solutions – like continuous reload.

Some time from now Qlik will introduce a solution for task chaining in Qlik SaaS, similar to what we know from QlikView. Before that happens, we can use Automations to achieve the result.
There is however an alternative by using APIs.

Current options

Consider a scenario where you have four Qlik Sense applications to regularly reload in sequence:

  • App 1,
  • then App 2,
  • then App 3,
  • then App 4.

Currently, the process involves creating three Automations. These Automations are set to listen for reload events in the tenant. An automation listens to reloads of a specific app and once it happens, it initiates the reload of the next app in sequence. For our example, this would necessitate creating three automations:

  • “reload App 2 after App 1”
  • “reload App 3 after App 2”
  • “reload App 4 after App 3”

While functional, these Automations are additional objects that need maintenance. They are also private and cannot be shared with other developers or administrators (Qlik will introduce shared automations some time from now). Moreover, if you operate in a dual environment (development and production), the number of required automations doubles to six.

A Better Solution: Utilizing Qlik APIs

Qlik APIs offer a robust solution, granting access to various endpoints for monitoring, managing, and creating resources. One such endpoint is the reloads endpoint, which can initiate the reload of a specific app.

Consider this simple Qlik Script code snippet for triggering a reload.

This script uses Qlik’s public API by connecting to it with a REST connection named “ApiPost“. Documentation on the reload endpoint can be found here https://qlik.dev/apis/rest/reloads.

Instructions

  1. Generate an API key or use an existing one. You need to be an admin with relevant privileges. For instructions look for “Managing API keys | Qlik Cloud Help”.
  2. Create a Data Connection of type REST with the following settings. For start, you need to provide a valid AppId (it will be reloaded when testing) but this AppId will then be substituted, with the WITH CONNECTION statement. Important settings are also 1. Method: POST and 2. Allow “WITH CONNECTION”.
  1. In the app that should trigger another app, paste the following code:
LIB CONNECT TO ':ApiPost';

Let vAppToReload = '6f67b6f1-4631-4e9d-938f-cf05400e2e55';

PostApiRequest:
SQL SELECT "id"
FROM JSON (wrap off) "data"
  WITH CONNECTION (  
    BODY "{""appId"":""$(vAppToReload)""}"
  )
;
  1. Update the vAppToReload variable to include the AppId of the app to be triggered. You will find the AppId in the url when opening the app or in its properties from the Hub. Notice how the vAppToReload is passed in the WITH CONNECTION – double-double quotes are needed (escaping).
  2. Reload the script!

Do more

More ideas and use cases:

  1. Continuous reload! If you coded App 1 to start App 2 ↻ and App 2 to start App 1 ↻… you would get a solution for continuous reload of an App! – normally unavailable with standard Qlik Sense SaaS scheduling.
  2. You can trigger multiple apps. The REST API call is not waiting for the result, you can use more calls in the same script. If you would like it to wait for the result, you would need to monitor the status using another API endpoint, in a loop, with a Sleep() command.
  3. You can use script control statements to conditionally trigger the reloads by forking from a condition. You can use the condition to provide a different AppId when the calling app is in a Shared or in a Managed space (development and production environments).