Forum Discussion

hugofernandes's avatar
hugofernandes
New Member
11 months ago
Solved

LocalStorage V2 always returning as undefined

I'm trying to develop an custom visual, and use the LocalStorage API, but when I try to define it in this.host.strageV2Service, it always return as undefined.   Is it active in admin panel? Yes. I...
  • dm-p's avatar
    11 months ago

    Hi hugofernandes,

     

    I replicated your setup using a new visual, and it looks fine in terms of how you're trying to access the API, but I had the same issues as you. This is weird, as I have built visuals for people using this API, so I know it works, but I dug further and found what is hopefully the same root cause as will be for you.

     

    Check your pbiviz.json, under apiVersion. If you've set up a brand new visual using the tools and haven't changed this, the tools set this to 5.3.0 by default, e.g.:

     

    {
        "visual": {
            "name": "storageTest",
            "displayName": "storageTest",
            "guid": "storageTestD056CAC136254AB789825C03790B59FA",
            "visualClassName": "Visual",
            "version": "1.0.0.0",
            "description": "",
            "supportUrl": "",
            "gitHubUrl": ""
        },
        "apiVersion": "5.3.0",    // <------ THIS RIGHT HERE
        "author": {
            "name": "",
            "email": ""
        },
        "assets": {
            "icon": "assets/icon.png"
        },
        "externalJS": null,
        "style": "style/visual.less",
        "capabilities": "capabilities.json",
        "dependencies": null,
        "stringResources": [],
        "version": "1.0.0.0"
    }

     

    If you try to access the V2 local storage API with this version, it will return as undefined, because it wasn't introduced until 5.8.0.

     

    If you set your apiVersion to "5.8.0" or higher (I used 5.9.1), stop your server and re-run the start task, the tools will install the relevant version of powerbi-visuals-api for you, e.g.:

     

     

    When you re-run this will now show in the console as defined, e.g.:

     

     

    You should then be able to continue to use as normal.

     

    Good luck!

     

    Daniel