Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW

How to: Loop and reduce with Qlik Application Automation (advanced) and Qlik Cloud

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

How to: Loop and reduce with Qlik Application Automation (advanced) and Qlik Cloud

Last Update:

May 8, 2023 3:15:21 AM

Updated By:

Sonja_Bauernfeind

Created date:

Sep 8, 2021 9:48:19 AM

Attachments
Loop and Reduce will remove an app's section access that was defined through the load script. Offline usage needs to be enabled in your tenant's management console in order to use the Loop And Reduce block on an app outside a personal space. More information on offline usage.

See How to Loop and Reduce with always one selected value fields if your app contains always one selected value fields.

This article explains how a loop and reduce operation can be performed on a Qlik Sense app by using Qlik Application Automation. It covers two examples, in the first one, the reloaded apps will be (re)published to one space. In the second example, each reduced app will be (re)published to a separate space.

This article covers two advanced examples, a more basic example can be found here .

Covered in this article:

 

The source app used in this article can be downloaded here.

Attached to this article are 2 files of the exported automations used in this article. More information on importing automations can be found here.

 

1. Loop and reduce to one space

In this example, all reduced apps will be (re)published to the same space.

Create a new automation and follow these steps to perform a loop and reduce action on a Qlik Cloud app:

  1. Go to the Qlik Cloud Services connector and search for the block "Loop And Reduce". Drag this block inside the automation editor.

  2. Specify the id for the app that should be used as a source app. The reduction will be performed on this app. Next, specify the field name over which the loop should run, for each unique value of the specified field name, a reduced app will be created. In this example, CountryName will be used as the reduction value.

    Emile_Koslowski_0-1664439097777.png

     

  3. The reduced apps are stored on the Temporary File services. The Loop And Reduce block will return a list of file ids together with the unique value of the reduction field and a list of sheet ids for the sheets that were public on the source app.

  4. The next step is to import the apps from the Temporary File services. To do this search for the block "Import App From Export Id" and drag this block in the loop that's created by the Loop And Reduce block. This block will import one app from the temporary file services into your personal space.
    Tip: specify the reduced value that's outputted by the Loop and Reduce block in the Name parameter of the Import block. See the below image for an example:

    Emile_Koslowski_1-1664439097781.png

     

  5. When an app is imported, all sheets will be made private, this is the default behavior of the import app block. The next step is to publish the sheets that were public in the source app.

  6. Because each reduced app will have a list of sheets that were public, a Loop block is necessary to loop over the list. Search for a "Loop" block in the block menu or find it under Basic and connect it right below the "Import App From Export Id" block. Specify the "Public Sheets" list returned by the Loop And Reduce block as the value for the "Loop over items of list" input parameter of the Loop block.

    Emile_Koslowski_2-1664439097782.png

     

  7. Now to publish each sheet of the imported app, search for the block "Publish Sheet" in the Qlik Cloud Services connector and drag that block in the loop generated by the "Loop" block. In this block, specify the id that's returned by the Import App block as App Id and use the current item in the loop as Sheet Id.

    Emile_Koslowski_3-1664439097783.png

     

  8. Nex step is to publish or republish the imported app to a managed space. This can be done with the block "Publish App To Managed Space". Search for this block in the Qlik Cloud Services connector and connect it below the loop block. Set the Run Mode to "(Re)publish by name", if the managed space already contains an app with the same name as the imported app, the imported app will be republished, or else it will be published.

  9. In the configuration of the Publish App To Managed Space block, set the App Id equal to the id returned by the Import App From Export Id block. For the Space Id, perform a lookup or manually enter an id, make sure you're specifying a managed space. The Data parameter should be set to "source".

    Emile_Koslowski_4-1664439097784.png

     

  10. Finally, when your app is published to a managed space, the imported app will still exist in your personal space. To remove this app, search for the block "Delete App" in the Qlik Cloud Services connector and connect it to the Publish App To Managed Space block. Specify the id returned by Import App From Export Id as the App Id in the block's settings.

An example of a completed automation:

Emile_Koslowski_5-1664439097785.png

 

Attached example file: loop_and_reduce_to_same_space.json

 

 

2. Loop and reduce to multiple spaces

In this example, each reduced app will be published to a different space. We'll use the Insurance Claims app and the automation for the first example again. Since this app reduces on the field CountryName, we'll start by creating a managed space for each unique value that's found for CountryName. This results in the following list of spaces:

Emile_Koslowski_6-1664439097787.png

 

Next is to create a mapping for each unique reduction value and the corresponding space's id. There are multiple ways to achieve this. In this example, this mapping is stored in a JSON list of objects with the keys reduction_value and space_id. Feel free to use an automation to create the managed spaces and build this list.

Example:

 

 

[
	{
		"reduction_value": "Scotland",
		"space_id": "6138a3062c1054d8158c189a"
	},
	{
		"reduction_value": "Northern Ireland",
		"space_id": "6138a318faed485d36ae911f"
	},
	{
		"reduction_value": "England",
		"space_id": "6138a337faed485d36ae9126"
	},
	{
		"reduction_value": "Wales",
		"space_id": "6138a33f98b0d0bf7e719dfb"
	},
	{
		"reduction_value": "Guernsey",
		"space_id": "6138a349faed485d36ae912b"
	},
	{
		"reduction_value": "Isle of Man",
		"space_id": "6138a35aba392246d331e611"
	},
	{
		"reduction_value": "Jersey",
		"space_id": "6138a3653ec592fe53a8d55b"
	}
]

 

 

 

The next step is to store the mapping in the automation. Execute the following steps to do this:

  1. Search for the Variable block and add this to the automation.

  2. Go to the block's settings, click Manage variables and add a new variable of type list.

  3. Go to the operations section of the variable and set the first operation to empty the variable.

  4. Add a second operation Merge other list into... and click the List input field of that operation, in the dropdown that appears, select Add Formula.

  5. From the formula picker, search for the formula Object and select it. Copy the JSON mapping to the json input field of the Object formula and click Save.

  6. Add the block to the beginning of the automation from the first part of this article:

    Emile_Koslowski_7-1664439097788.png

     

  7. The next step is to find the right space id for each reduced app. To do that, add the block Lookup Item In List in the automation right before the block Publish App To Managed Space.

  8. Go to the settings of the Lookup Item In List block and specify the variable that contains space_id/reduction_value mapping as input list. The condition inside the lookup should compare the mapping's reduction_value to the Reduced Value of the current item in the loop of Loop And Reduce. See the below image for an example:


    Emile_Koslowski_8-1664439097789.png

     

  9. Finally, specify the space_id from the output of the lookup block as Space Id in the settings of the Publish App To Managed Space.

    Emile_Koslowski_9-1664439097790.png

     

Attached example file: loop_and_reduce_to_mulitple_spaces.json

 

 

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.

Labels (2)
Comments
Tanalex
Creator II
Creator II

Does any type of solution exist for on-prem?  ODAG?  Something else?  Thank you! 

Emile_Koslowski
Employee
Employee

No, Qlik Application Automation is only available for Qlik Sense Enterprise for SaaS.

Tanalex
Creator II
Creator II

Bummer, but thank you for the clarification. 

JaniSullanmaa
Contributor II
Contributor II

Great content @Emile_Koslowski !

Are there any plans to make this actually "enterprise-ready"? By that I mean that now it takes a great deal of manual work and complexity to actually make a loop&reduce that is trustworthy and does what it needs to do.

Disabling the section access in the reduce is the worst thing here, as it's not usually enough to limit visibility based on the slice alone.

Deactivating and Reactivating AOSV-fields manually adds work and likelyhood of mistakes, there can be 1-N of those fields in one app. And one needs to re-apply the default selected value as well.

Due to the above, you need to import to somewhere else before completing the steps and only then publish. That means also publishing sheets, adding descriptions..It's a complex automation for a fairly simple use case.

So basically, when can we get a similar plug-and-play that we had in Qlikview? 

Spartan27215
Partner - Creator
Partner - Creator

Why can't you just have an automation to create the spaces? It can easily create the spaces based on the same reduction value and create the Id automatically.

In fact, why create the spaces ahead of time at all? The spaces could be easily created using the reduction value or some other formula and updated based on that as well. Resulting in one loop that will both create and update the spaces as needed.

Spartan27215
Partner - Creator
Partner - Creator

What happens if I only want to create less spaces that I have loop values I guess I have to build each one separately. 

Sonja_Bauernfeind
Digital Support
Digital Support

Hello @Spartan27215 

I recommend posting your query directly in our Qlik Application Automation forum to make use of the wider reach into our community and our active support engineers.

All the best,
Sonja 

Michael_Leigh
Employee
Employee

To clarify an earlier response to a question: Loop and Reduce is available for Qlik Sense on-premise via the Application Management Console (AMC). Application Automation is not available for on-premise.

Application Management Console 

Version history
Last update:
‎2023-05-08 03:15 AM
Updated by: