Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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!
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
}
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
}
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.