Qlik Community

Qlik Sense Integration, Extensions, & APIs

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

Partner
Partner

ApplyPatches doesn't work

Hi everyone

I'm trying to use the ApplyPatches() API to modifiy the Calculation Condition of a measure in a table, but I can't get it to work.

I'm using the Engine API explorer in the dev-hub (but also tested with the .NET SDK and I get the same error). This is the request in the engine API explorer:

image.png

 

And the response I get back from the engine is:

image.png

How do I make this work?

NOTE: I've already tried to wrap the string in double quotes (like so: \"'1'\") but I get the same exact error.

 

1 Solution

Accepted Solutions
ErikWetterberg
Honored Contributor

Re: ApplyPatches doesn't work

Hi Master,

I have created a small table with 3 measures to try this. The correct way to do this is the command:

{
  "handle": 2,
  "method": "ApplyPatches",
  "params": {
  "qPatches": [
    {
      "qOp": "replace",
      "qPath": "/qHyperCubeDef/qMeasures/2/qCalcCondition/qCond/qv",
      "qValue": "\"1\""
   }
  ],
   "qSoftPatch": false
  }
}

Which works.

If I change to:

"qValue": "\'1\'"

the Engine API explorer won't even let me send that, because it's not valid JSON.

5 Replies
ErikWetterberg
Honored Contributor

Re: ApplyPatches doesn't work

Single quote (‘) is not a valid string delimiter in JSON, use double quote (“) only.

Also qOp should be one of add, replace or remove.

Check the documentation:

https://help.qlik.com/en-US/sense-developer/June2018/apis/EngineAPI/definitions-NxPatch.html

 

Partner
Partner

Re: ApplyPatches doesn't work

Hello Erik, thanks for your reply but the problem is not with the single quotes. That value is just an example, but I did further tests with all kinds of value, and what I concluded is this: ApplyPatches is not working on ANY MEASURE DEFINITION in the hypercube. I can apply patches correctly on other properties of the hypercube, but as soon as I try on a property inside one of the measures, no matter if it's a string, number or boolean value, I get that error. Also note that I already tried using "replace" instead of "2" (the two should be equivalent tho) 

ErikWetterberg
Honored Contributor

Re: ApplyPatches doesn't work

Hi Master,

I have created a small table with 3 measures to try this. The correct way to do this is the command:

{
  "handle": 2,
  "method": "ApplyPatches",
  "params": {
  "qPatches": [
    {
      "qOp": "replace",
      "qPath": "/qHyperCubeDef/qMeasures/2/qCalcCondition/qCond/qv",
      "qValue": "\"1\""
   }
  ],
   "qSoftPatch": false
  }
}

Which works.

If I change to:

"qValue": "\'1\'"

the Engine API explorer won't even let me send that, because it's not valid JSON.

Highlighted
ErikWetterberg
Honored Contributor

Re: ApplyPatches doesn't work

Another thing that could be the problem is the number 6 in your path. That would be measure #7, since #0 is the first one. Have you got 7 measures in your table?

For finding the right path to the applyPatches command you could use my Chrome extension available in Chrome web store: https://chrome.google.com/webstore/detail/add-sense/bbiljflfafkaejgdebbnmcohpidgkejj

Using it you can inspect properties for objects and switch to the patch mode, which gives you properties as a filterable list, with the path.

More info here:

http://upper88.com/addsensechrome.html

Partner
Partner

Re: ApplyPatches doesn't work

Hello Erik

Thanks again for your support, really appreciated.

As it turns out, something must've gone wrong with my Qlik Sense. After rebooting the server ApplyPatches started working again, even with the single quotes, like this:

\"'1'\"

(note that the single quotes were INSIDE of the string in the last line of my first post, so they should've worked... in yours they didn't because you tried to escape the single quotes, instead of the double quotes, which is indeed a syntax error )

Thanks again!