Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
rbartley
Specialist II
Specialist II

Extracting all visualizations in an app

Hello everyone,

I'm thinking of writing a script to automate the creation of mashups and to start I thought I'd use the Engine API to extract the IDs and types of all visualizations within an app.  Does anyone know if there's a way to do this without using the GetObjects method of a document and specifying every type of visualization?  When I specify the object type, I get the result I expect, while when I pass an empty qTypes option, it returns an empty reply:

This works:

 

 

 

{
	"handle": 1,
	"method": "GetObjects",
	"params": {
		"qOptions": {
			"qTypes": [
				"barchart"
			],
			"qIncludeSessionObjects": false,
			"qData": {}
		}
	}
}

 

 

and returns:
 

 

 

{
	"jsonrpc": "2.0",
	"id": 5,
	"delta": true,
	"result": {
		"qList": [
			{
				"qInfo": {
					"qId": "bbb31edd-f836-4bb1-a826-7a230d14f760",
					"qType": "barchart"
				},
				"qMeta": {
					"title": "xxxx",
					"description": "",
					"tags": []
				},
				"qData": {}
			},
			{
				"qInfo": {
					"qId": "98e3d4a1-8e2f-40df-8f80-55e40072dc74",
					"qType": "barchart"
				},
				"qData": {}
			}
		]
	}
}

 

 

 
 
This doesn't:
 

 

{
	"handle": 1,
	"method": "GetObjects",
	"params": {
		"qOptions": {
			"qTypes": [
				""
			],
			"qIncludeSessionObjects": false,
			"qData": {}
		}
	}
}

 

 

Returns:

 

{
	"jsonrpc": "2.0",
	"id": 6,
	"delta": true,
	"result": {
		"qList": []
	}
}

 

 

Is there a wildcard or keyword that would allow me to retrieve all visualizations, regardless of the type?

 

Thanks in advance.

 

Regards,

 

Richard

Labels (2)
1 Solution

Accepted Solutions
Aiham_Azmeh
Employee
Employee

your probably need to do GetObject => GetLayout for each one of them individually.

View solution in original post

12 Replies
Aiham_Azmeh
Employee
Employee

Hi @rbartley ,

There are no wildcards, so you need to list all the type in the array, but obviously you will miss the custom types (3rd party visualization extensions).

I would recommend you to list all sheets & cells instead:

[
  {
    "name": "SHEETLIST",
    "method": "CreateSessionObject",
    "handle": "${dochandle}",
    "params": [
        {
          "qInfo": {
            "qType": "SheetList"
          },
          "qAppObjectListDef": {
            "qType": "sheet",
            "qData": {
              "cells": "/cells"
            }
          }
        }
    ]
  },
  {
    "method": "GetLayout",
    "handle": "${SHEETLIST.result.qReturn.qHandle}",
    "params": []
  }
]

You should be able to transform the result object into the list of objectIds that are consumed in the app

 

I hope this helps,

rbartley
Specialist II
Specialist II
Author

Hi @Aiham_Azmeh ,

 

Thanks for your response.  This is very useful.  Could you tell me how the order of the items in the response is determined?  For example, is it ordered from top left of a sheet to bottom right or by the time when the visualization was added?  Is there a way of determining relative position of each visualization within a sheet?

Regards,

 

Richard

 

Aiham_Azmeh
Employee
Employee

Hi @rbartley ,

There is no order, the position is calculated with through rows and cols placement.

Below you have the code snippet we use in single integration for recreating a sheet:

getSheetHtml(sheetLayout) {
    const height = sheetLayout.height || 100;
    let html = `<div style="position:relative;width:100%;height: ${height}%;" class="qvt-sheet">`;
    let cols = 0;
    let rows = 0;
    sheetLayout.cells.forEach(function(v) {
      cols = Math.max(cols, v.col + v.colspan);
      rows = Math.max(rows, v.row + v.rowspan);
    });
    sheetLayout.cells.forEach(function(v) {
      let style = 'position:absolute;';
      if (v.bounds) {
        const b = v.bounds;
        style += `left: ${b.x}%;`;
        style += `top: ${b.y}%;`;
        style += `width: calc(${b.width}% - 10px);`;
        style += `height: calc(${b.height}% - 10px);`;
        style += 'margin: 5px';
        html += `<div style="${style}" data-qid="${v.name}" col="${v.col}" row="${v.row}"></div>`;
      } else {
        style += `left: ${(v.col * 100) / cols}%;`;
        style += `top: ${(v.row * 100) / rows}%;`;
        style += `width: calc(${(v.colspan * 100) / cols}% - 10px);`;
        style += `height: calc(${(v.rowspan * 100) / rows}% - 10px);`;
        style += 'margin: 5px';
        html += `<div style="${style}" data-qid="${v.name}" col="${v.col}" row="${v.row}"></div>`;
      }
    });
    html += '</div>';
    return html;
  },

 This may help,

/aiham

rbartley
Specialist II
Specialist II
Author

Hi aiham @Aiham_Azmeh , 

Thanks for your reply.  In the first line of your getSheetHtml function you have 

 

 

sheetLayout.height

 

 

However, I do not appear to have a height property in the result of either the CreateSessionObject method or the GetLayout method.  

 

 

 

sheetsObject= 
{jsonrpc: "2.0", id: 3, result: {…}}
id: 3
jsonrpc: "2.0"
result:
qLayout:
qAppObjectList:
qItems: Array(3)
0:
qData:
cells: Array(7)
0: {name: "e9246f16-9e9f-4fb4-a00a-bd92ed7b9add", type: "filterpane", col: 4, row: 0, colspan: 10, …}
1: {name: "13e0ff36-6dd8-457e-b718-c4f74a1af710", type: "qsSimpleKPI", col: 14, row: 0, colspan: 4, …}
2: {name: "bbb31edd-f836-4bb1-a826-7a230d14f760", type: "barchart", col: 11, row: 1, colspan: 13, …}
3: {name: "12d8901e-a7f5-4494-a01c-d6b97a8fb0c6", type: "qlik-tabbed-container", col: 0, row: 1, colspan: 11, …}
4: {name: "83bc44a7-a56c-41d3-a091-abde7accb15d", type: "qlik-button-for-navigation", col: 18, row: 0, colspan: 3, …}
5: {name: "BfYjW", type: "SimpleFieldSelect", col: 0, row: 0, colspan: 4, …}
6: {name: "BUEmaf", type: "com-qliktech-screenshottopdf_app", col: 21, row: 0, colspan: 3, …}
length: 7
__proto__: Array(0)
__proto__: Object
qInfo: {qId: "a0dc4ad1-6d0d-43c3-bd72-661e701bea50", qType: "sheet"}
qMeta:
approved: true
createdDate: "2019-06-21T09:49:01.605Z"
description: ""
draftObject: ""
modifiedDate: "2019-09-02T16:37:49.283Z"
owner: {id: "6e06e227-8817-4c0d-a8c6-5dd1b766643e", userId: "XXXXX", userDirectory: "XXXXX", name: "XXXXXX", privileges: null}
privileges: (5) ["read", "update", "delete", "publish", "approve"]
publishTime: "2019-06-21T09:49:02.776Z"
published: true
qSize: -1
sourceObject: ""
title: "Absolute (Heads/Tonnes)"

 

Could you please confirm which object you are passing to your getSheetHtml function?

 

Thanks in advance.

 

Regards,

 

Richard

 

rbartley
Specialist II
Specialist II
Author

Hi aiham @aaz ,

 

Also, is it possible to determine the number of fields in a filterpanel by using the Engine API?

 

Thanks in advance,

 

Richard

rbartley
Specialist II
Specialist II
Author

I see that I can get this information (number of fields in a filter pane) by calling the GetObject method, passing the qId(s) of the filterpane(s) as a parameter and then calling GetLayout.  This returns:

 

{
	"jsonrpc": "2.0",
	"id": 6,
	"delta": true,
	"result": {
		"qLayout": {
			"qInfo": {
				"qId": "e9246f16-9e9f-4fb4-a00a-bd92ed7b9add",
				"qType": "filterpane"
			},
			"qSelectionInfo": {},
			"qChildList": {
				"qItems": [
					{
						"qInfo": {
							"qId": "bd9c9e17-7fc9-47a3-8bfb-6b96f9a4bdfa",
							"qType": "listbox"
						},
						"qData": {
							"info": ""
						}
					},
					{
						"qInfo": {
							"qId": "29ea0fc0-13cd-41da-afd6-efb179ee2ff1",
							"qType": "listbox"
						},
						"qData": {
							"info": ""
						}
					},
					{
						"qInfo": {
							"qId": "8daada98-5543-4731-91b4-e97afb96362a",
							"qType": "listbox"
						},
						"qData": {
							"info": ""
						}
					}
				]
			},
			"showTitles": false,
			"title": "",
			"subtitle": "",
			"footnote": "",
			"visualization": "filterpane"
		}
	}
}

 

Aiham_Azmeh
Employee
Employee

It's the sheet layout:

return app.getObject(sheetId)
      .then(function(sheetModel) {
        return sheetModel.getLayout()
          .then(function(sheetLayout) {
              [.....]

I am not 100% sure when the `height` appears, I will try to find out.

rbartley
Specialist II
Specialist II
Author

@Aiham_Azmeh 

 

Hi,

The sheet list only seems to return the filterpane, not the filterpane contents (the lists inside the filterpane).  

 

 

Aiham_Azmeh
Employee
Employee

your probably need to do GetObject => GetLayout for each one of them individually.