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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
kenwang
New Member

persistProperties and stored data persistency

Hi, I have read through some of the past questions on persistProperties. I managed to get it working to some extend but I am facing the following behaviour

 

In edit mode, when saved (using persistProperties), visual refresh will persist the changes. When I switch between PowerBI report tabs, the data will persist as well.

 

However, when I do a browser refresh (F5), the changes will not persist. I think I am missing something really simple here.

 

capabilities.json

 

"saved": {
            "displayName": "Saved",
            "displayNameKey": "Saved",
            "properties": {
                "savedJSON": {
                    "displayName": "Saved JSON",
                    "displayNameKey": "Visual_savedJSON",
                    "type": {
                        "text": true
                    }
                }
            }
        }

 

 

My save function

 

    private save() {
        let _this = this;
        let objects: powerbi.VisualObjectInstancesToPersist = {
            merge: [
                <VisualObjectInstance>{
                    objectName: "saved",
                    selector: null,
                    properties: {
                        "savedJSON": JSON.stringify(_this.savedJSON)
                    }
                }]
        };
        this.host.persistProperties(objects);
        console.log("saved");
    }

 

 

 

 

1 ACCEPTED SOLUTION

Hi @kenwang,

Properties are only intended to be persisted in edit mode, as they are bound the the visual's metadata and are not user-specific, so a save is required to the report for them to remain.

If you have multiple people reading the report and setting their preferences, this would result in everyone's changes getting lost one ofter the other (if this were possible) as you can't guarantee when the report was last opened by a user, and what state the properties were in when they did, meaning that earlier changes from one user might be overwritten by another user.

This is the kind of thing that something like cookies are ideal for, but unfortunately they are not enabled in the visual sandbox.

Ii's possible that the local storage API might be something that could be leveraged, but this has a high bar to entry (visual must be certified and whitelisted by visuals team).

Other than that, it might be possible to store/retrieve user preferences via web services, but this comes with its own security challenges, particularly if wanting to submit to AppSource, as you'd need to ensure reliability and security of such an infrastructure, as well as establishing some kind of user-specific token. Additionally if you were submitting to AppSource and looking to certifiy, this would count as an external call and would be likely to fail.

In short, I don't think so, there is, unfortunately 😞 But, you could try asking the team directly if they have any other thoughts on this - pbicvsupport@microsoft.com

Regards,

Daniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




View solution in original post

4 REPLIES 4
dm-p
Super User
Super User

Hi @kenwang,

If you're refreshing the browser, have you ensured that you’ve saved the report first? It looks like you are persisting correctly (as you've confirmed that objects are preserved nd restored when navigating pages prior ro refresh - this means that the props can be correctly retrieved when the constructor runs, which is all you should need to worry about) but if you don't save the report before refreshing the entire web page then this is essentially reloading the entire report without saving changes. This would have the same effect for any visual, custom or otherwise. I'd suggest testing saving the report before you reload the page and hopefully this should work for you.

If you're using F5 to try to refresh the visual, you should actually click the reload button on the visual itself rather than the entire page, as there is no hotkey bound to this and you'd ideally want to avoid refreshing the entire page (and report) unless there's a very specific reason for doing so.

Regards, 

Daniel 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




Thank you. I'll mark this as answer. You have given me a lot to think about.

Thank you and much appreciated. Yes indeed, if I clicked "save" before refreshing, the properties will persist.

 

Maybe I am tackling my requirements wrong. What I am trying to do is to have user's interaction perserved (without going into edit mode). I wonder if this is possible at all.

 

What is happening is that I am implementing an initial auto-layout to display objects on a chart (when it's first loaded). The users are however, encouraged to "drag" the items to their position of choice. I am trying to preserve the user's choice. Will this be possible?

 

Regards,

 

Kenneth

 

 

Hi @kenwang,

Properties are only intended to be persisted in edit mode, as they are bound the the visual's metadata and are not user-specific, so a save is required to the report for them to remain.

If you have multiple people reading the report and setting their preferences, this would result in everyone's changes getting lost one ofter the other (if this were possible) as you can't guarantee when the report was last opened by a user, and what state the properties were in when they did, meaning that earlier changes from one user might be overwritten by another user.

This is the kind of thing that something like cookies are ideal for, but unfortunately they are not enabled in the visual sandbox.

Ii's possible that the local storage API might be something that could be leveraged, but this has a high bar to entry (visual must be certified and whitelisted by visuals team).

Other than that, it might be possible to store/retrieve user preferences via web services, but this comes with its own security challenges, particularly if wanting to submit to AppSource, as you'd need to ensure reliability and security of such an infrastructure, as well as establishing some kind of user-specific token. Additionally if you were submitting to AppSource and looking to certifiy, this would count as an external call and would be likely to fail.

In short, I don't think so, there is, unfortunately 😞 But, you could try asking the team directly if they have any other thoughts on this - pbicvsupport@microsoft.com

Regards,

Daniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


My course: Introduction to Developing Power BI Visuals


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.