How to: task chaining with Qlik Application Automation
This article explains how to perform task chaining for your QCS apps using Qlik Application Automation. It'll start with a simple app reload example and finishes with a complex task chain example.
Reloading QCS apps
Sync vs async reloads
Basic task chain
Task chain with condition
Task chain with a loop
Task chain with a loop and condition
1. Reloading QCS apps
Create a new automation and follow these steps to reload a QCS app:
Go to the Qlik Cloud Services connector and search for the "Do Reload" block. Drag this block inside the editor and attach it to the Start block.
Click on the newly added block to highlight it and display the block details menu on the right side of the editor. Go to the inputs tab of this block and enter the App Id for the QCS app you want to reload.
It is also possible to do a lookup for your app. Click the empty input field for App Id and click "Do Lookup" in the dropdown that appears. This will fetch a list of all the QCS apps you have access to, select the app you want to reload.
For now, you can ignore the other input fields. Click the green Run button to execute the automation.
Result in the editor:
The output from the Do Reload block contains information about the reload. The "status" field for example will indicate whether the reload was successful.
2. Sync vs async reloads
Reloads can either be done synchronous or asynchronous. This is configured by selecting a value for the field "Run Mode" in the inputs tab of the Reloads block.
Async: set the Run Mode to "Start reload and continue". When executed, the block will trigger a reload and output the reload id. The automation will continue immediately. Use the reload id in the block "Get Reload Record" to get the reload's status.
Sync: set the Run Mode to "Wait for reload to complete". When the block is executed, the automation won't continue until the reload is finished. Once the reload is finished the block will output the reload's result and the automation will continue.
3. Basic task chain
Now for a basic task chain, drag an additional "Do Reload" block in the editor and attach it to the automation.
Go to the Inputs tab in the first Reloads block and set the Run Mode to "Wait for reload to complete". This way, the second reload block will only execute once the first reload block is finished.
4. Task chain with a condition
In the previous example, the second reload will always execute once the first reload is finished. Regardless of the result. In some cases, you might only want to start the second reload when the first reload finished successfully.
Search for the "Condition" block and attach it between the 2 reload blocks.
Go inside the inputs tab on the Condition block and set the Input field of the "if" statement. From the dropdown that appears, select "output from Do Reload" and click on the "status" field.
Next, select the condition of the "if" statement and set it to "equals". A new input field will appear. Here you should specify the value you expect to receive in the Reload's status field. In this example, we only want to do the second reload if the first one was successful so we'll set this value to "SUCCEEDED".
Now drag the second Do Reload block to the "Yes" part of the Condition block.
Finally, add a comment to the Condition block so its function is clear without having to open it and look at the actual condition.
In some cases, you'll want to trigger multiple app reloads to start simultaneously. And wait for all of them to finish before continuing the automation.
Clear your automation or create a new one and drag a "Variable" block in it. This variable will contain a list of app ids for all the apps to reload.
Go to the Inputs tab on the Variable block and click the "Manage variables" button to add new variables. Add a variable of name "AppIds" and type "List". Click Save.
Select the new variable as the value for the Variable input parameter in the Inputs tab.
Click "Add operation" in the variable's input tab and select "Empty AppIds" as the first operation that needs to happen when this block is executed. It's a good practice to empty a variable before using it.
Add a new operation, this time select "Add item to AppIds". Enter the id of one of the apps that need to reload.
Repeat the above step 5 for each app that needs reloading.
Next, we'll need to loop over the list of app ids. Search for the "Loop" block and attach it to the Variable block.
Go to the inputs tab of the Loop block and specify the list variable. (This should have happened automatically)
Search for a "Do Reload" block and add it to the automation inside the loop of the Loop block.
Go to the inputs tab of the Do Reload block and map the App Id field to the Item in the loop. Set the Run Mode to "Start reload and continue".
Now we somehow need to keep track of the ids of all the reloads that were started. To do this, add a new variable block to the automation right after the "Variable - AppIds" block. Again, go to Manage variables and add a new variable with the name "ReloadIds" and type "List". Set this variable as the active variable in the Variable input parameter and add "Empty ReloadIds" as an operation.
Drag another Variable block inside the automation and add it right after the "Do Reload" block in the loop.
Select ReloadIds as the Variable for that block. And add a new operation "Add item to ReloadIds". Click the input field for the Item's value and select the Id that's returned from the "Do Reload" block.
The next block we'll need is the "Wait For Reloads To Complete" block from the Qlik Cloud Services connector. Add this block to the automation after the loop.
Go to this block's inputs tab and map the ReloadIds list variable to the "Reload Ids" input parameter. This input parameter expects a comma-separated list. So after mapping it, click the ReloadIds mapping and select "Add Formula".
Search for the "Implode" formula and select it. This formula will transform the list into a comma-separated string. Click "Save" to add the formula.
This part continues on the automation that was created in part 5. "Task chain with a loop".
In most use cases, what happens after the parallel reloads will depend on the returned results. To do this, we'll need to filter the results from the "Wait For Reloads To Complete" block.
Search for the "Filter List" block and attach it after the Wait For Reloads To Complete block.
Map the output from the Wait For Reloads To Complete block as input for the List parameter. And set the condition to "If status does not equal SUCCEEDED". Now the Filter List block will output all the unsuccesful reloads.
Next, add a Condition block after the Filter list block. Set the condition to "If Filter List is empty". If this condition is true, (the Yes part) then all reloads were successful. Else (the No part) some reloads failed.
Feel free to fill in both the Yes and No part of the Condition block, depending on your use case.
Maybe you want to start a new reload only if all reloads were successful? Then add a new Do Reload block to the Yes part of the condition.
Or if you want to alert your team on the result, you can use blocks from the Email, Slack, or Teams connectors to populate both the Yes and No part
A JSON file containing the above automation is attached to this article as parallel_task_chain_with_condition.json How to import an automation