Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Dec 20, 2023 7:21:06 AM
Feb 8, 2022 6:04:50 AM
This article explains how the Save App to block can be used to distribute changes made in an automation's session to other sessions (for example, the Qlik Sense UI). Before you continue with this article it is advised to have a good understanding of how Qlik Application Automation interacts with the Qlik engine and the QIX API. This article is a good start for that: Automation session delays.
As explained in the session delays article, automations will create sessions for certain interactions with apps. When this is done, the following rule applies:
An automation creates a unique session per automation, per run, per app.
The changes made by these operations are scoped to the automation's session and will only be distributed to other sessions (including the Qlik Sense UI) after 20-40 minutes.
In some situations, you might want to make these changes available immediately in the other sessions. To do this, the Save App block can be used.
The Save App block will execute the DoSave method in the QIX API. This method will save an app, its objects, and data in the data model from the current session. And it will load the app again in all open sessions.
The usage of this block has two drawbacks:
Heavy computation
This can be computationally heavy and should only be done we the changes need to be distributed immediately to all active sessions. Know that they will eventually sync automatically after 20-40 minutes.
Only one execution/session
The usage of the Save App block is limited to one execution for every active session. In the context of an automation, this translates to one execution for every app that was modified by a session block. It's advised to execute the Save App block once for every affected app at the end of your automation.
If the Save App block is used multiple times for the same session, it will only work the first time.
A list of blocks that use the QIX API (session blocks) can be found at the end of this article.
More info on the DoSave method can be found here.
1. Basic
In the below example, a few measures are added to an app. The Create Measure block is a session block, so its changes aren't immediately distributed to other sessions.
We can use the Save App block to distribute these changes. And since all changes are made to the same app, only one session is used and the Save App block needs to be executed only once.
2. Multiple sessions
The automation in the below example will create a new measure in two different apps. This means the automation will create two sessions, one for every app.
So the Save App block needs to be executed twice.
3. Loops
In this example, we'll list measures from a source app and distribute (create or update) them to all apps in a space. This automation will create the following sessions:
No changes are made to the source app, so session distribution is not required, executing a Save App block for this app is a waste of resources.
To make sure a Save App block is executed for every created measure, we can add this block as the last step inside the loop:
4. Multiple loops
This time, we'll use 2 source apps and we'll distribute their measures again to all the apps in a target space. As you see in the example below, it's not feasible to add the Save App block after the Create Measure block as it will be executed multiple times for the same application (which won't work as explained in the previous section).
You'll probably be able to rewrite the above automation so it has a place for the Save App block. But that won't always be an option, especially for bigger automations. Trying to fit in a Save App block in the middle of an automation will also increase its complexity.
The easiest solution here is to list the apps from the target space again at the end of the automation and execute the Save App block in the List Apps block's loop.
The information in this article is provided as-is and to be used at own discretion. Depending on tool(s) used, customization(s), and/or other factors ongoing support on the solution below may not be provided by Qlik Support.