Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
mountaindude
Partner Ambassador
Partner Ambassador

Creating per-value-colors for master dimensions using the engine API

I am trying to create master dimensions with associated per-value-colors using the engine API
The use case is for client-managed Qlik Sense (for now).

Creating the master dimension works, but I fail finding any info on how to create the needed ColorMap object using the engine API. I can read those color maps for existing master dimensions, but just not figure out how to create new or update existing color maps.

I guess it would be a two-step process...?

First  create the color map and get a ID for it, then create/update the master dimension, including a reference to that color map ID.

Any wizzes or Qlik employees who can share how this works?

Thx!

Please mark the post as a solution if it provided you with a solution to the topic at hand. Thanks!
Labels (2)
1 Solution

Accepted Solutions
alex_colombo
Employee
Employee

Hi @mountaindude I tried to reproduce what's native UI does. Basically, when you create your dimension, colors are assigned automatically. Then, you can change them calling a couple of engine API methods.

First create create a dimension as below

{
	"handle": 1,
	"method": "CreateDimension",
	"params": {
		"qProp": {
			"qInfo": {
				"qType": "dimension"
			},
			"qDim": {
				"qGrouping": "N",
				"qFieldDefs": [
					"Dim1"
				],
				"title": "Dim1",
				"qFieldLabels": [
					"Dim1"
				]
			},
			"qMetaDef": {
				"title": "Dim1",
				"description": "",
				"tags": []
			}
		}
	},
	"outKey": -1,
	"id": 3
}

 

From above response you have to get the created dimension ID, we need it in next calls.

Then create a ColorMap object where you will set your custom colors for your dimension values. Here you need to set dimension ID for qId attribute.

{
	"handle": 1,
	"method": "CreateObject",
	"params": {
		"qProp": {
			"qInfo": {
				"qType": "ColorMap",
				"qId": "ColorMapModel_yourDimensionID"
			},
			"colorMap": {}
		}
	},
	"outKey": -1,
	"id": 4
}

 

As final step, from ColorMap object created in previous step, you have to use SetProperties method where you can define your custom colors in colors array

{
	"handle": 3,
	"method": "SetProperties",
	"params": {
		"qProp": {
			"qInfo": {
				"qId": "ColorMapModel_yourDimensionID",
				"qType": "ColorMap"
			},
			"qExtendsId": "",
			"qMetaDef": {},
			"qStateName": "",
			"colorMap": {
				"colors": [
					{
						"value": "A",
						"baseColor": {
							"color": "#85ac6b",
							"index": -1
						}
					}
				],
				"nul": null,
				"oth": null,
				"pal": null,
				"single": null,
				"usePal": true,
				"autoFill": true
			}
		}
	},
	"outKey": -1,
	"id": 5
}

 

View solution in original post

2 Replies
alex_colombo
Employee
Employee

Hi @mountaindude I tried to reproduce what's native UI does. Basically, when you create your dimension, colors are assigned automatically. Then, you can change them calling a couple of engine API methods.

First create create a dimension as below

{
	"handle": 1,
	"method": "CreateDimension",
	"params": {
		"qProp": {
			"qInfo": {
				"qType": "dimension"
			},
			"qDim": {
				"qGrouping": "N",
				"qFieldDefs": [
					"Dim1"
				],
				"title": "Dim1",
				"qFieldLabels": [
					"Dim1"
				]
			},
			"qMetaDef": {
				"title": "Dim1",
				"description": "",
				"tags": []
			}
		}
	},
	"outKey": -1,
	"id": 3
}

 

From above response you have to get the created dimension ID, we need it in next calls.

Then create a ColorMap object where you will set your custom colors for your dimension values. Here you need to set dimension ID for qId attribute.

{
	"handle": 1,
	"method": "CreateObject",
	"params": {
		"qProp": {
			"qInfo": {
				"qType": "ColorMap",
				"qId": "ColorMapModel_yourDimensionID"
			},
			"colorMap": {}
		}
	},
	"outKey": -1,
	"id": 4
}

 

As final step, from ColorMap object created in previous step, you have to use SetProperties method where you can define your custom colors in colors array

{
	"handle": 3,
	"method": "SetProperties",
	"params": {
		"qProp": {
			"qInfo": {
				"qId": "ColorMapModel_yourDimensionID",
				"qType": "ColorMap"
			},
			"qExtendsId": "",
			"qMetaDef": {},
			"qStateName": "",
			"colorMap": {
				"colors": [
					{
						"value": "A",
						"baseColor": {
							"color": "#85ac6b",
							"index": -1
						}
					}
				],
				"nul": null,
				"oth": null,
				"pal": null,
				"single": null,
				"usePal": true,
				"autoFill": true
			}
		}
	},
	"outKey": -1,
	"id": 5
}

 

mountaindude
Partner Ambassador
Partner Ambassador
Author

Yeah I got it working too by looking at the traffic in the websocket between the Sense UI and backend server.
Works well once you decode all those messages flowing back and forth. 

All good thus!

Btw, the use case was to add color support for bulk import of master dimensions/measure to the open source Ctrl-Q tool.
Latest release (yesterday, 3.9) includes such color support, which makes it a breeze to define master items textually in an Excel file, then import them with a single command to one (or more) apps.

Master-items-as-code, kind of.
Blog post describing the whole thing here.

Please mark the post as a solution if it provided you with a solution to the topic at hand. Thanks!