Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
rbecher
MVP
MVP

Backend Api getProperties / setProperties

Hi,

I'm looking for examples how to use this.backendApi.getProperties() / setProperties() methods. Anything on this?

- Ralf

Astrato.io Head of R&D
1 Solution

Accepted Solutions
ErikWetterberg

I'm afraid this doesn't work. The getPropertries is asynchronous, and does not return properties, but a promise.

It's a bit more complicated, but you can do something like this:

var me = this;

this.backendApi.getProperties().then(function(reply){

        reply.title = 'New title';

        me.backendApi.setProperties(reply);

});

View solution in original post

16 Replies
Not applicable

You can find all the relevant documentation on the Qlik Sense help site http://help.qlik.com or for this specific question look here https://help.qlik.com/sense/en-us/developer/index.html#../Subsystems/Workbench/Content/BuildingExten...

rbecher
MVP
MVP
Author

But there is no example for getProperties / setProperties..

Astrato.io Head of R&D
Not applicable

Use

myprops = this.backendApi.getProperties();

this.backendApi.setProperties(myprops);

rbecher
MVP
MVP
Author

Thanks, this was clear so far. But how access/set a property in myprops?

Astrato.io Head of R&D
rbecher
MVP
MVP
Author

Hi Stefan,

but this is not for this.backendApi.getProperties() ?

Best regards,

Ralf

Astrato.io Head of R&D
Not applicable

Actually its very similar, the structure you retrieve is the qProp structure in the json response for getProperties, and the first item in the params array for setProperties

The only difference is that the javascript methods in backendAPI strips away the rest.

But I agree with you the Examples are missing and should be added. I'll file a request for it.

ErikWetterberg

I'm afraid this doesn't work. The getPropertries is asynchronous, and does not return properties, but a promise.

It's a bit more complicated, but you can do something like this:

var me = this;

this.backendApi.getProperties().then(function(reply){

        reply.title = 'New title';

        me.backendApi.setProperties(reply);

});

ErikWetterberg

Another option would be to use the applyPatches method. This allows you to change properties without fetching them first (getProperties is not needed)

self.backendApi.applyPatches([{

                        "qPath" : "/title",

                        "qOp" : "replace",

                        "qValue" : "\"New title\""

                    }], true);

                   

The last parameter is th softpatch flag: if you set it to true, the change will be regarded as temporary and not persisted.

Note the format of the qValue parameter: this is actually a JSON value inside a string (since you can patch strings, numbers or JSON objects). In this case we want to set a string value, and so we need double citation marks. If we wanted to set a number (not valid in the title) it should be something like "qValue": "-1".