5 Replies Latest reply: May 4, 2018 4:41 PM by Jonathan Vitale RSS

    ApplyPatches - Valid Properties?

    Jonathan Vitale

      Hello all,

       

      I'm using the ApplyPatches method of the Engine API to update a generic object (a visualization such as a combo chart).

      I am using this method on any arbitrary set of properties of the object, but the method seems to fail for a large number of properties.

      It is not clear which properties can be updated. The documentation here

      https://help.qlik.com/en-US/sense-developer/September2017/Subsystems/EngineAPI/Content/Classes/GenericObjectClass/Generi…

      Says that "some" properties can be patched.

       

      Is there a list of patch-able properties somewhere?

       

      Jonathan

        • Re: ApplyPatches - Valid Properties?
          Erik Wetterberg

          Hi,

          I have used ApplyPatches a lot and never come across properties that cannot be patched. What happens? Do you get an error message? Or does it simply not work? It's more likely there is a format problem with your patch.

           

          Can you share an example?

           

          Erik Wetterberg

            • Re: ApplyPatches - Valid Properties?
              Jonathan Vitale

              Ah, this is what I did wrong:

               

              I was passing a batch set of definitions to patch an object. So, I wasn't getting the individual error messages for each patch, just a broad fail. When I tried each patch individually in the API Explorer I see the problem. Basically, I am trying to patch a value in an array that does not exist (but could in theory). Here's an example with a combochart.

               

              {
              "handle": 4,
              "method": "ApplyPatches",
              "params": {
              "qPatches": [
              {
              "qOp": "replace",
              "qPath": "/qHyperCubeDef/qMeasures/1",
              "qValue": "{\"qLibraryId\":\"\"}"
              }
              ],
              "qSoftPatch": false
              }
              }
              
              
              
              

               

              The error is, "Illegal Array Index. Out of bounds"

               

              Basically, because a combo-chart could have two measures my algorithm tries to patch it, but in this case my chart only has one measure, so the second index of the qMeasures array is not defined yet.

               

              Hopefully, this is the only problem. Thanks again.

                • Re: ApplyPatches - Valid Properties?
                  Erik Wetterberg

                  Hi,

                  I'm not absolutely sure about this, but I think qOp: "add" works in most cases. I also use JSON.stringify to format the value to avoid having to escape chars etc.

                   

                  And I'm glad you use the Engine API explorer, something of a forgotten tool...

                   

                  Erik Wetterberg

                  • Re: ApplyPatches - Valid Properties?
                    Jonathan Vitale

                    I also noticed another problem, for future reference:

                     

                    If the value that needs to be patched is stored as a number, patching with a string will cause a failure.

                    So for example:

                     

                    "params": {
                    "qPatches": [
                    {
                    "qOp": "replace",
                    "qPath": "/qHyperCubeDef/qMeasures/0/qDef/qNumFormat",
                    "qValue": "{\"qUseThou\":\"0\"}"
                    }
                    ],
                    

                     

                    The qUseThou can be 0 or 1 or true or false but "0" causes an error.

                  • Re: ApplyPatches - Valid Properties?
                    Jonathan Vitale

                    erik.wetterberg

                     

                    I found another issue. Perhaps you can weigh in:

                     

                    Let's say we have a path within the json for a KPI object to a key like "conditionalColoring". There are several key-value pairs inside this object. Like this (retrieved with GetFullPropertyTree, only relevant part displayed):

                     

                    "conditionalColoring": {
                      "useConditionalColoring": false,
                      "singleColor": 3,
                      "segments": {
                        "limits": [],
                        "colors": [
                         {
                         "color": 2
                         }
                       ]
                      }
                    },
                    

                     

                    If I want to patch only one of these key-value pairs, like "singleColor", I might try this ApplyPatches method (in Engine API Explorer):

                     

                    "qPatches": [
                    {
                      "qOp": "replace",
                      "qPath": "/qHyperCubeDef/qMeasures/0/qDef/conditionalColoring",
                      "qValue": "{\"singleColor\":3}"
                    }
                    ],
                    

                     

                    While this successfully replaces the "singleColor" key, it removes everything else.

                     

                    "conditionalColoring": {
                       "singleColor": 3
                    }
                    

                     

                    I could successfully fill in all the values by specifying the full sub-tree like this in my ApplyPatches call:

                    "qPatches": [
                    {
                    "qOp": "replace",
                    "qPath": "/qHyperCubeDef/qMeasures/0/qDef/conditionalColoring",
                    "qValue": "{\"singleColor\":3, \"useConditionalColoring\":false, \"colors\":[{\"color\":2}]}"
                    }
                    ],
                    

                     

                    Using JSON.stringify would help here, but this kind of defeats the purpose of "ApplyPatches". I don't want to have to update every value in the object, I just want to patch a single key-value pair.