microsoft / PowerBI-visuals-tools

Contains tools for building/packaging Power BI visuals
https://www.powerbi.com
MIT License
337 stars 152 forks source link

powerbi-client + custom visual. Setting border value #507

Closed swiecaJS closed 8 months ago

swiecaJS commented 9 months ago

I want to set the border on my custom-built visual programmatically. It works perfectly when changed via powerbi web app (or desktop)

However, as soon as I try to use powerbi-client library I get an error. The same code works without an issue on the build-in visuals.

My code:

export const setActiveBorder = async (visual: VisualDescriptor | undefined) => {
  try {
    await visual?.setProperty(
      {
        objectName: 'border',
        propertyName: 'visible',
      },
      {
        value: true,
      },
    )

    await visual?.setProperty(
      {
        objectName: 'border',
        propertyName: 'radius',
      },
      {
        value: 8,
      },
    )
    await visual?.setProperty(
      {
        objectName: 'border',
        propertyName: 'color',
      },
      {
        value: '#ff0000',
      },
    )
  } catch (error) {
    console.error('setting active border failed', error)
  }
}

Error message:

{
    "message": "setPropertyFailed",
    "detailedMessage": "Set visual property failed"
}

The same behavior happens with the blank new visual created through pbiviz new, making the error easy to replicate. powerbi-client repo does not accept the issues, so I am leaving an issue here, because I believe the problem lies somewhere at the intersection

AleksSavelev commented 9 months ago

Hello @swiecaJS,

I'm not sure why do you use setProperty in this case. Are there any reasons to do so?

Usually you can simply change the value of the setting directly in getFormattingModel. Please, take a look on this documentation

swiecaJS commented 9 months ago

@AleksSavelev my reports are embedded on a webpage with the use of powerbi-client library.

setProperty is a part of power bi client API, see documenation

swiecaJS commented 9 months ago

To have a clear reproduction step

  1. Create a blank visual with pbiviz create
  2. Put that visual on a report
  3. Open that report in the embed mode, for example by using playground
  4. Try to change the border using setProperty
  5. Error happens
AleksSavelev commented 9 months ago

Oh, I see. Could you, please, contact us on email pbicvsupport@microsoft.com and describe this issue one more time. Support guys will add the responsible team to the discussion.

AleksSavelev commented 8 months ago

I'll close the issue as it's not related to the tools itself, but feel free to contact the support email with any questions.