Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
rbartley
Specialist II
Specialist II

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

1 Solution

Accepted Solutions
ErikWetterberg

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/

View solution in original post

7 Replies
ErikWetterberg

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/

rbartley
Specialist II
Specialist II
Author

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
Specialist II
Specialist II
Author

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?

ErikWetterberg

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/

rbartley
Specialist II
Specialist II
Author

Thanks again Erik.

Diego_Busilacchi
Contributor II
Contributor II

Hello!

I need to use applyPatches method to change some dimension property in a pivot table.

Does anyone have a properties.js file to do that?

Thanks!