<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic LocalStorage V2 always returning as undefined in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/LocalStorage-V2-always-returning-as-undefined/m-p/4818292#M62997</link>
    <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it active in admin panel? Yes.&lt;/P&gt;&lt;P&gt;Is added in the cappabilities.json? Yes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="pbi undefined.png" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1295995iF3CF6C91211E24F6/image-size/large?v=v2&amp;amp;px=999" role="button" title="pbi undefined.png" alt="pbi undefined.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code i'm trying to run:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;"use strict";

import powerbi from "powerbi-visuals-api";
import { FormattingSettingsService } from "powerbi-visuals-utils-formattingmodel";
import "./../style/visual.less";

import VisualConstructorOptions = powerbi.extensibility.visual.VisualConstructorOptions;
import VisualUpdateOptions = powerbi.extensibility.visual.VisualUpdateOptions;
import IVisual = powerbi.extensibility.visual.IVisual;
import IVisualLocalStorageV2Service = powerbi.extensibility.IVisualLocalStorageV2Service; 
import StorageV2ResultInfo = powerbi.extensibility.StorageV2ResultInfo; 
import PrivilegeStatus = powerbi.PrivilegeStatus; 
import ILocalVisualStorageService = powerbi.extensibility.ILocalVisualStorageService;


import { VisualFormattingSettingsModel } from "./settings";

export class Visual implements IVisual {
    private target: HTMLElement;
    private textNode: Text;
    private host: powerbi.extensibility.visual.IVisualHost;
    private formattingSettings: VisualFormattingSettingsModel;
    private formattingSettingsService: FormattingSettingsService;
    private filters: any[] = [];
    private messages: string = "";
    
    private storageV2Service: IVisualLocalStorageV2Service; 
    private storage: ILocalVisualStorageService;
    private storageName: string = "testePbi";
    private valueStorage: string = "";

    constructor(options: VisualConstructorOptions) {
        this.host = options.host;
        this.storageV2Service = this.host.storageV2Service;
        console.log("constructor", this.storageV2Service); // always undefined
    }

    private handleIframeOnload() {
        const iframe = this.target.querySelector("iframe");
        if (iframe?.contentWindow) {
            iframe.contentWindow.postMessage({
                type: "FILTER_UPDATE",
                filters: this.filters
            }, "*");
        }
    }

    public update(options: VisualUpdateOptions) {
        if (!this.storageV2Service) {
            this.storageV2Service = this.host.storageV2Service;
            console.log("update", this.storageV2Service); // always undefined
        }
    }

    /**
     * Returns properties pane formatting model content hierarchies, properties and latest formatting values, Then populate properties pane.
     * This method is called once every time we open properties pane or when the user edit any format property. 
     */
    public getFormattingModel(): powerbi.visuals.FormattingModel {
        return this.formattingSettingsService.buildFormattingModel(this.formattingSettings);
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My capabilities.json:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
    "dataRoles": [
        {
            "displayName": "Category Data",
            "name": "category",
            "kind": "Grouping"
        },
        {
            "displayName": "Measure Data",
            "name": "measure",
            "kind": "Measure"
        }
    ],
    "objects": {
        "dataPoint": {
            "properties": {
                "defaultColor": {
                    "type": {
                        "fill": {
                            "solid": {
                                "color": true
                            }
                        }
                    }
                },
                "showAllDataPoints": {
                    "type": {
                        "bool": true
                    }
                },
                "fill": {
                    "type": {
                        "fill": {
                            "solid": {
                                "color": true
                            }
                        }
                    }
                },
                "fillRule": {
                    "type": {
                        "fill": {}
                    }
                },
                 "fontSize": {
                    "type": {
                        "formatting": {
                            "fontSize": true
                        }
                    }
                }
            }
        }
    },
    "dataViewMappings": [
        {
            "categorical": {
                "categories": {
                    "for": {
                        "in": "category"
                    },
                    "dataReductionAlgorithm": {
                        "top": {}
                    }
                },
                "values": {
                    "select": [
                        {
                            "bind": {
                                "to": "measure"
                            }
                        }
                    ]
                }
            }
        }
    ],
    "privileges": [
        {
            "name": "WebAccess",
            "essential": true,
            "parameters": [
                "http://localhost:3000",
                "http://127.0.0.1:5500",
                "http://localhost:5500",
                "http://localhost:5173"
            ]
        },
        {
            "name": "LocalStorage",
            "essential": true
        }
    ]
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 05 Sep 2025 14:05:07 GMT</pubDate>
    <dc:creator>hugofernandes</dc:creator>
    <dc:date>2025-09-05T14:05:07Z</dc:date>
    <item>
      <title>LocalStorage V2 always returning as undefined</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/LocalStorage-V2-always-returning-as-undefined/m-p/4818292#M62997</link>
      <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it active in admin panel? Yes.&lt;/P&gt;&lt;P&gt;Is added in the cappabilities.json? Yes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="pbi undefined.png" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1295995iF3CF6C91211E24F6/image-size/large?v=v2&amp;amp;px=999" role="button" title="pbi undefined.png" alt="pbi undefined.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code i'm trying to run:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;"use strict";

import powerbi from "powerbi-visuals-api";
import { FormattingSettingsService } from "powerbi-visuals-utils-formattingmodel";
import "./../style/visual.less";

import VisualConstructorOptions = powerbi.extensibility.visual.VisualConstructorOptions;
import VisualUpdateOptions = powerbi.extensibility.visual.VisualUpdateOptions;
import IVisual = powerbi.extensibility.visual.IVisual;
import IVisualLocalStorageV2Service = powerbi.extensibility.IVisualLocalStorageV2Service; 
import StorageV2ResultInfo = powerbi.extensibility.StorageV2ResultInfo; 
import PrivilegeStatus = powerbi.PrivilegeStatus; 
import ILocalVisualStorageService = powerbi.extensibility.ILocalVisualStorageService;


import { VisualFormattingSettingsModel } from "./settings";

export class Visual implements IVisual {
    private target: HTMLElement;
    private textNode: Text;
    private host: powerbi.extensibility.visual.IVisualHost;
    private formattingSettings: VisualFormattingSettingsModel;
    private formattingSettingsService: FormattingSettingsService;
    private filters: any[] = [];
    private messages: string = "";
    
    private storageV2Service: IVisualLocalStorageV2Service; 
    private storage: ILocalVisualStorageService;
    private storageName: string = "testePbi";
    private valueStorage: string = "";

    constructor(options: VisualConstructorOptions) {
        this.host = options.host;
        this.storageV2Service = this.host.storageV2Service;
        console.log("constructor", this.storageV2Service); // always undefined
    }

    private handleIframeOnload() {
        const iframe = this.target.querySelector("iframe");
        if (iframe?.contentWindow) {
            iframe.contentWindow.postMessage({
                type: "FILTER_UPDATE",
                filters: this.filters
            }, "*");
        }
    }

    public update(options: VisualUpdateOptions) {
        if (!this.storageV2Service) {
            this.storageV2Service = this.host.storageV2Service;
            console.log("update", this.storageV2Service); // always undefined
        }
    }

    /**
     * Returns properties pane formatting model content hierarchies, properties and latest formatting values, Then populate properties pane.
     * This method is called once every time we open properties pane or when the user edit any format property. 
     */
    public getFormattingModel(): powerbi.visuals.FormattingModel {
        return this.formattingSettingsService.buildFormattingModel(this.formattingSettings);
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My capabilities.json:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
    "dataRoles": [
        {
            "displayName": "Category Data",
            "name": "category",
            "kind": "Grouping"
        },
        {
            "displayName": "Measure Data",
            "name": "measure",
            "kind": "Measure"
        }
    ],
    "objects": {
        "dataPoint": {
            "properties": {
                "defaultColor": {
                    "type": {
                        "fill": {
                            "solid": {
                                "color": true
                            }
                        }
                    }
                },
                "showAllDataPoints": {
                    "type": {
                        "bool": true
                    }
                },
                "fill": {
                    "type": {
                        "fill": {
                            "solid": {
                                "color": true
                            }
                        }
                    }
                },
                "fillRule": {
                    "type": {
                        "fill": {}
                    }
                },
                 "fontSize": {
                    "type": {
                        "formatting": {
                            "fontSize": true
                        }
                    }
                }
            }
        }
    },
    "dataViewMappings": [
        {
            "categorical": {
                "categories": {
                    "for": {
                        "in": "category"
                    },
                    "dataReductionAlgorithm": {
                        "top": {}
                    }
                },
                "values": {
                    "select": [
                        {
                            "bind": {
                                "to": "measure"
                            }
                        }
                    ]
                }
            }
        }
    ],
    "privileges": [
        {
            "name": "WebAccess",
            "essential": true,
            "parameters": [
                "http://localhost:3000",
                "http://127.0.0.1:5500",
                "http://localhost:5500",
                "http://localhost:5173"
            ]
        },
        {
            "name": "LocalStorage",
            "essential": true
        }
    ]
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Sep 2025 14:05:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/LocalStorage-V2-always-returning-as-undefined/m-p/4818292#M62997</guid>
      <dc:creator>hugofernandes</dc:creator>
      <dc:date>2025-09-05T14:05:07Z</dc:date>
    </item>
    <item>
      <title>Re: LocalStorage V2 always returning as undefined</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/LocalStorage-V2-always-returning-as-undefined/m-p/4819200#M63014</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/1349681"&gt;@hugofernandes&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Check your &lt;FONT face="courier new,courier"&gt;pbiviz.json&lt;/FONT&gt;, under &lt;FONT face="courier new,courier"&gt;apiVersion&lt;/FONT&gt;. If you've set up a brand new visual using the tools and haven't changed this, the tools set this to&amp;nbsp;&lt;STRONG&gt;5.3.0&lt;/STRONG&gt; by default, e.g.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;{
    "visual": {
        "name": "storageTest",
        "displayName": "storageTest",
        "guid": "storageTestD056CAC136254AB789825C03790B59FA",
        "visualClassName": "Visual",
        "version": "1.0.0.0",
        "description": "",
        "supportUrl": "",
        "gitHubUrl": ""
    },
    "apiVersion": "5.3.0",    // &amp;lt;------ 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"
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you try to access the V2 local storage API with this version, it will return as &lt;FONT face="courier new,courier"&gt;undefined&lt;/FONT&gt;, because &lt;A href="https://learn.microsoft.com/en-us/power-bi/developer/visuals/changelog#api-v580" target="_self"&gt;it wasn't introduced until 5.8.0&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dmp_1-1757278487176.png" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1296296i26257551891E68E7/image-size/large?v=v2&amp;amp;px=999" role="button" title="dmp_1-1757278487176.png" alt="dmp_1-1757278487176.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you re-run this will now show in the console as defined, e.g.:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dmp_0-1757278464839.png" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/1296295iB1E5BAD6B61C5229/image-size/large?v=v2&amp;amp;px=999" role="button" title="dmp_0-1757278464839.png" alt="dmp_0-1757278464839.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should then be able to continue to use as normal.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Daniel&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Sep 2025 20:57:55 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/LocalStorage-V2-always-returning-as-undefined/m-p/4819200#M63014</guid>
      <dc:creator>dm-p</dc:creator>
      <dc:date>2025-09-07T20:57:55Z</dc:date>
    </item>
    <item>
      <title>Re: LocalStorage V2 always returning as undefined</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/LocalStorage-V2-always-returning-as-undefined/m-p/4819224#M63015</link>
      <description>&lt;P&gt;Upgrading the version worked, thanks!!!&lt;/P&gt;&lt;P&gt;I didn't pay attention to the release date of the api, and in the documentation wasn't mentioning anything about it either, thanks!!!&lt;/P&gt;</description>
      <pubDate>Mon, 08 Sep 2025 00:59:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/LocalStorage-V2-always-returning-as-undefined/m-p/4819224#M63015</guid>
      <dc:creator>hugofernandes</dc:creator>
      <dc:date>2025-09-08T00:59:48Z</dc:date>
    </item>
    <item>
      <title>Re: LocalStorage V2 always returning as undefined</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/LocalStorage-V2-always-returning-as-undefined/m-p/4819228#M63016</link>
      <description>&lt;P&gt;Hey,&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/608865"&gt;@DataNinja777&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;If i add the "StorageV2" instead of "LocalStorage" returns the error:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt; error  should be equal to one of the allowed values .privileges[2].name
 error  Invalid capabilities&lt;/LI-CODE&gt;&lt;P&gt;The error itself was the package version, that was using the 5.3.0 instead of the more recent that has this api&amp;nbsp;implemented.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for recommending the best practices and sending a base code!&lt;/P&gt;&lt;P&gt;Will adjust my code to follow it!&lt;/P&gt;</description>
      <pubDate>Mon, 08 Sep 2025 01:04:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/LocalStorage-V2-always-returning-as-undefined/m-p/4819228#M63016</guid>
      <dc:creator>hugofernandes</dc:creator>
      <dc:date>2025-09-08T01:04:37Z</dc:date>
    </item>
    <item>
      <title>Re: LocalStorage V2 always returning as undefined</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/LocalStorage-V2-always-returning-as-undefined/m-p/4819229#M63017</link>
      <description>&lt;P&gt;It's a huge misstep in the documentation, as far as I'm concerned, as it tripped me up as well to the point where I was convinced it was broken and I was going to recommend you create a support issue &lt;span class="lia-unicode-emoji" title=":grinning_face_with_sweat:"&gt;😅&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Glad you're up and running though!&lt;/P&gt;</description>
      <pubDate>Mon, 08 Sep 2025 01:04:55 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/LocalStorage-V2-always-returning-as-undefined/m-p/4819229#M63017</guid>
      <dc:creator>dm-p</dc:creator>
      <dc:date>2025-09-08T01:04:55Z</dc:date>
    </item>
    <item>
      <title>Re: LocalStorage V2 always returning as undefined</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/LocalStorage-V2-always-returning-as-undefined/m-p/4820462#M63039</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/1349681"&gt;@hugofernandes&lt;/a&gt;, the comment you responded to has been removed.&amp;nbsp; I'm glad you were able to find a solution to your question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;Natalie H.&lt;/P&gt;
&lt;P&gt;Community Manager&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Sep 2025 18:28:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/LocalStorage-V2-always-returning-as-undefined/m-p/4820462#M63039</guid>
      <dc:creator>Natalie_iTalent</dc:creator>
      <dc:date>2025-09-08T18:28:45Z</dc:date>
    </item>
  </channel>
</rss>

