Tobias Jung
Tobias Jung

Reputation: 33

PowerBI Desktop Custom Visual - Storage Problem

i developed an custom filter for iso calender weeks for my company in PowerBI.

It works very well, but i am not able to save the current filter to the localstorage. It works on the web when its published but not in the desktop version.

import ILocalVisualStorageService = powerbi.extensibility.ILocalVisualStorageService;



constructor(options: VisualConstructorOptions){
    this.storage = options.host.storageService;
}
 

in my first update cycle i check for the localstorage and set if necessary.

//to get data in async function
let cache = await this.storage.get("filter");


//to set data in async function
await this.storage.set("filter", "xyz");
 

Is it possible to use the localstorage in Desktop?

Kind Regards

Tobias

Upvotes: 1

Views: 591

Answers (1)

BlackbirdSLO
BlackbirdSLO

Reputation: 76

Did you try contacting Power BI visuals support to activate the local storage API, as it is not activated by default?

https://learn.microsoft.com/en-us/power-bi/developer/visuals/local-storage

Alternatively, for your use case it might be better to use the persistProperties service. There is very little documentation about this feature on the PBI Visuals documentation website, but you can find an example in powerbi-visuals-sankey custom visual, where it is used to store various properties.

https://github.com/microsoft/powerbi-visuals-sankey

A rough example for your case:

options.host.persistProperties({
            VisualObjectInstance = {
            objectName: "filterSetting",
            selector: undefined, 
            properties: {
                filter: "xyz"
            }
        };
     });

After triggering the persistProperties function, the visual triggers an update, populating the VisualUpdateOptions' options.dataViews.metadata.objects with the persisted property. Note, that you have to define your property in the capabilities.json beforehand.

Upvotes: 1

Related Questions