Forum Discussion

xuyonggang's avatar
xuyonggang
New Member
2 years ago

How to get the options.dataViews[0] in the constructor

I need to call the passed Measures when the visual object is initialized, but when the object is created in the constructor, the data will not be updated, so I don't know if there is a way to get VisualUpdateOptions.dataViews, or if there is a way to force update data.

 

please help me, thx~

5 Replies

  • dm-p's avatar
    dm-p
    Super User

    Hi xuyonggang,

     

    If your visual contains measures in the data view, then Power BI will automatically run the update method, making the data view available to your visual's logic.

     

    If you want your visual to trigger the update method without the presence of measures in the data view, then you can look at the landing page APIs. This will force the visual to run both the constructor and the update methods sequentially when the visual is initialized without data.

     

    If your requirement is outside this, I'm struggling to understand your case for needing this. Can you perhaps explain a bit more why this is important? What does your constructor need to do with the dataview that the update method cannot handle?

     

    Regards,

     

    Daniel

    • xuyonggang's avatar
      xuyonggang
      New Member

      Hi, dm-p, glad for your reply, but i find run the update method is not helpful for my visual.  
      My visual object only needs to call the measurement value during initialization, and then get other values through the operation of the visual object, these values also will overwrite the measures【measures just only serve as default values ​​for initialization】. If I write the initialization into the update function, this will cause it to be reset every time when data updated. This is not What I want, so what I need most is “How to get the options.dataViews[0] in the constructor"

      • dm-p's avatar
        dm-p
        Super User

        Hi xuyonggang,

         

        Unless you can think within the constraints of the current visual lifecycle, and this is something you truly need, your current approach will be to create a feature request with Microsoft. There is no way to do this currently.

         

        You can create an issue here: Issues · microsoft/PowerBI-visuals-tools (github.com)

         

        Regards,

         

        Daniel