Qlik Community

Qlik Sense Integration, Extensions, & APIs

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

rbartley
Contributor III

Qlik Sense Mashup - using applyPatches to change measure

Hi everyone,

I am having an issue trying to use the applyPatches method to change the measure in a pivot table.  I have been able to change the sort order and various other properties, but I assume there is a problem with the syntax of the JSON I am using:

var patches = [{

'qPath': '/layout/qHyperCubeDef/qMeasures/0',

'qOp': 'replace',

'qValue': '{\'qDef\':\'Sum(Value)\'}'

}];

vis.applyPatches( patches, true );

The error I am getting is:

applyPatches Change Measure.PNG

I have also tried without "layout" in the path, but I still get the error message.  Depending on the qValue entry, I can also get a slightly different error message:

applyPatches Change Measure 2.PNG

Any help would be gratefully received.

Richard

Tags (2)
1 Solution

Accepted Solutions
erik_wetterberg
Honored Contributor

Re: Qlik Sense Mashup - using applyPatches to change measure

Hi Richard,

You're right there should be no '/layout' in your path, the path starts with '/qHyperCubeDef'. (You are actually not patching the layout but the properties structure). A good way to find to path is to use the /options/developer switch to inspect the objects properties. You will find something like this:

Capture.PNG

So the path will be '/qHyperCubeDef/qMeasures/0/qDef/qDef' (yes,there should be two qDef).

The value should be a string in a string, something like '"Sum(Value)"'. You could also use JSON.stringify, but that's more if you need a structure with several properties.

Hope this helps

Erik Wetterberg

https://extendingqlik.upper88.com/

Erik Wetterberg
https://extendingqlik.upper88.com/
6 Replies
erik_wetterberg
Honored Contributor

Re: Qlik Sense Mashup - using applyPatches to change measure

Hi Richard,

You're right there should be no '/layout' in your path, the path starts with '/qHyperCubeDef'. (You are actually not patching the layout but the properties structure). A good way to find to path is to use the /options/developer switch to inspect the objects properties. You will find something like this:

Capture.PNG

So the path will be '/qHyperCubeDef/qMeasures/0/qDef/qDef' (yes,there should be two qDef).

The value should be a string in a string, something like '"Sum(Value)"'. You could also use JSON.stringify, but that's more if you need a structure with several properties.

Hope this helps

Erik Wetterberg

https://extendingqlik.upper88.com/

Erik Wetterberg
https://extendingqlik.upper88.com/
rbartley
Contributor III

Re: Qlik Sense Mashup - using applyPatches to change measure

Excellent response as always Erik.  Also, thanks for the /options/developer tip.

I was confusing the layout with the properties, as you say, and forgetting the second qDef.  In the end, the following code works:

var strMeasure= '"Sum(Value)"';

var patches = [{

'qPath': '/qHyperCubeDef/qMeasures/0/qDef/qDef',

"qOp": "replace",

'qValue':   strMeasure

}];

vis.applyPatches( patches, true );

rbartley
Contributor III

Re: Qlik Sense Mashup - using applyPatches to change measure

One more thing Erik.  Is it possible to apply more than one change, e.g. change measures and chart title in the same call to applyPatches?  If so, what would the syntax look like?

erik_wetterberg
Honored Contributor

Re: Qlik Sense Mashup - using applyPatches to change measure

Sure, that's why it's an array. Just add some more patches to the array, the same syntax(qPath, qOp, qValue) for all of them. You can also use objects, if you for example want to change the sort order or something. In that case JSON.stringify is your friend.

Erik Wetterberg

https://extendingqlik.upper88.com/

Erik Wetterberg
https://extendingqlik.upper88.com/
rbartley
Contributor III

Re: Qlik Sense Mashup - using applyPatches to change measure

Thanks again Erik.

erik_wetterberg
Honored Contributor

Re: Qlik Sense Mashup - using applyPatches to change measure

You find more info on the developer menu here:

Developer menu in Qlik Sense client

Erik Wetterberg

https://extendingqlik.upper88.com/

Erik Wetterberg
https://extendingqlik.upper88.com/
Community Browser