Qlik Community

Qlik Sense Integration, Extensions, & APIs

Discussion board where members can learn more about Integration, Extensions and API’s for Qlik Sense.

Announcements
See why Qlik is recognized as a Leader for the 10th year in a row – and discover how Qlik can help put your business in the lead. Get Report
Highlighted
ramnellutla
New Contributor II

How to make selections while creating a bookmark using the engine api

I am planning to export bookmarks from a Qlik server and then import them on to other server using Qlik API. I was able to export bookmarks which looked like below:

 

				"qInfo": {
					"qId": "b7c8511b-f567-470e-b46c-6ac549b4f8c2",
					"qType": "bookmark"
				},
				"qMeta": {
					"title": "ExamFinalDateLast60Days",
					"description": "ExamFinalDateLast60Days\n=ExamFinalDate>=today()-60",
					"createdDate": "2019-12-02T17:27:41.787Z",
					"modifiedDate": "2020-01-24T21:12:11.388Z",
					"published": true,
					"publishTime": "2019-12-06T13:17:37.953Z",
					"approved": true,
					"owner": {
						"id": "221defd5-ef78-4db0-84f7-9de0066061f0",
						"userId": "sairam.nellutla",
						"userDirectory": "R3",
						"name": "f.l",
						"privileges": null
					},
					"qSize": -1,
					"sourceObject": "",
					"draftObject": "",
					"privileges": [
						"read",
						"exportdata",
						"approve"
					]
				},
				"qData": {
					"qBookmark": {
						"qStateData": [
							{
								"qStateName": "$",
								"qFieldItems": [
									{
										"qDef": {
											"qName": "ExamFinalDate",
											"qType": "NOT_PRESENT"
										},
										"qSelectInfo": {
											"qTextSearch": "=ExamFinalDate>=today()-60",
											"qRangeLo": "NaN",
											"qRangeHi": "NaN",
											"qNumberFormat": {
												"qType": "U",
												"qnDec": 10,
												"qUseThou": 0
											},
											"qRangeInfo": [],
											"qContinuousRangeInfo": []
										},
										"qValues": [],
										"qExcludedValues": []
									}
								]
							}
						],
						"qUtcModifyTime": 43595.39157407408,
						"qVariableItems": []
					}
				}

 

 

With the above information, I am trying to create a bookmark on an other server using the 'CreateBookmark' method.
Based on the engine api explorer, the 'CreateBookmark' method takes the following parameters:

 

{
	"handle": 1,
	"method": "CreateBookmark",
	"params": {
		"qProp": {
			"qInfo": {
				"qId": "",
				"qType": ""
			},
			"qMetaDef": {}
		}
	}
}

 


I was able to create a bookmark by adding 'qInfo' and providing 'title' and 'description' as shown below but I am not able to figure out how the dimensions (qFieldItems in the exported book mark above) are provided in the parameter list while creating a bookmark using the 'CreateBookmark' method.

 

{
	"handle": 1,
	"method": "CreateBookmark",
	"params": {
		"qProp": {
			"qInfo": {
				"qId": "7f70d955-cffb-4063-8a30-aa05100e731e",
				"qType": "bookmark"
			},
			"qMetaDef": {
					"title": "testbookmar2",
					"description": "testbookmar2 desc"
                         }
       }
}

 

 

The 'qMetaDef' field in the parameter list is 'NxMetaDef' type with no structure as per the docs. Any help on what goes in to the 'CreateBookmark' method to specify dimensions is highly appreciated.

2 Replies
ErikWetterberg
Honored Contributor

Re: How to specify dimensions while creating a bookmark using the engine api

CreateBookmark creates a bookmark based on your current selections. So to import a bookmark you need to apply the selections first. Not an easy task

 

Highlighted
ramnellutla
New Contributor II

Re: How to specify dimensions while creating a bookmark using the engine api

This trick worked for the dynamic bookmarks. For dynamic bookmarks, GetBookmarks() method also returned the expression of the bookmark. With the available information from the GetBookmarks() method, I was able to the get the field using the GetField() method and select the columns by providing the match (again obtained from the GetBookmarks() method) in the Select() method. After performing the same in all fields and doing CreateBookmark() automatically added the expression with selections.

However, this is limited to bookmarks that are created with expression (by searching in the list box). It does not work for book marks that are created by making the selections in the UI. Here is a sample code:

 

 

                for qs in bookmark["qData"]['qBookmark']['qStateData']:
                    for qFieldItem in qs["qFieldItems"]:
                        fieldName = qFieldItem["qDef"]["qName"]
                        textSearch = qFieldItem["qSelectInfo"]["qTextSearch"]
                        getFieldParams = {}
                        getFieldParams["qFieldName"] = fieldName
                        field = await self.qlikConnectionObj.send("GetField", self.openApp.qHandle, getFieldParams)
                        selectParams = {}
                        selectParams["qMatch"] = textSearch
                        selectParams["qSoftLock"] = False
                        selectParams["qExcludedValuesMode"]: 0
                        await self.qlikConnectionObj.send("Select", field["result"]["qReturn"]["qHandle"], selectParams)
                createBookmarkParams = {}
                createBookmarkParams["qProp"] = {}
                createBookmarkParams["qProp"]["qInfo"] = bookmark['qInfo']
                createBookmarkParams["qProp"]["qMetaDef"] = {}
                createBookmarkParams["qProp"]["qMetaDef"]["title"] = bookmark['qMeta']['title']
                await self.qlikConnectionObj.send("CreateBookmark", self.openApp.qHandle, createBookmarkParams)