进行更改后将 Power BI 嵌入式报表保存在数据库中 [英] Save Power BI embedded report in Database after making changes

查看:105
本文介绍了进行更改后将 Power BI 嵌入式报表保存在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 power bi 嵌入式包来嵌入 power bi 报告 - https://github.com/microsoft/powerbi-client-react

报告嵌入在编辑模式中,因此用户可以创建或编辑报告.现在我有一个保存按钮,一旦用户对 power bi 报告进行更改,我想将报告保存在数据库中.你能告诉我如何触发报告事件.看起来允许的保存事件不起作用.

此外,如果我必须在用户进行更改或创建报告后获取报告的实例,我该如何再次获取报告的实例以反映新的更改?

',embedUrl: '<嵌入网址>',accessToken: '<访问令牌>',令牌类型:models.TokenType.Embed,视图模式:models.ViewMode.Edit,设置:{窗格:{过滤器:{扩展:假,可见:假}},背景:models.BackgroundType.Transparent,}}}事件处理程序 = {新地图([['加载', function () {console.log('报告加载');}],['渲染', function () {console.log('报告渲染');}],['error', function (event) {console.log(event.detail);}]])}cssClassName = {报告样式类";}getEmbeddedComponent = { (embeddedReport) =>{this.report = EmbeddedReport 作为报告;}}/>

报告已正确嵌入,但现在有人进行更改后,如何再次获取更新的报告实例,以便获取视觉效果并将其存储在数据库中?

解决方案

目前,power-client-react 不支持创建新报告.但是,您可以使用此库编辑现有报告并将其另存为新报告.为此,您需要执行以下步骤:

  1. 生成嵌入令牌:

    • 如果要将报告更改保存为新报告,请在生成嵌入令牌请求中传递以下 JSON 正文:

      <块引用>

      <代码>{访问级别":编辑",allowSaveAs":真",}

    • 如果要将报告更改保存在同一报告中,请在生成嵌入令牌请求中传递以下 JSON 正文:

      <块引用>

      <代码>{访问级别":编辑",}

  2. 嵌入报告 - 在您的 embedConfig 对象中添加这些配置:

    <块引用>

    viewMode:models.ViewMode.Edit,权限:models.Permissions.All,

  3. 处理已保存"事件:

    • 如果要将报告更改保存为新报告,请在 eventHandlers 映射中添加以下事件处理程序以获取新报告 ID,然后嵌入新报告以获取其实例:

      <块引用>

      ['saved', function (event) {var newReportId = event.detail.reportObjectId);}]

    • 如果要将报告更改保存在同一报告中,请在您的 eventHandlers 映射中添加以下事件处理程序,以确保更改已保存:

      <块引用>

      ['saved', function (event) {console.log(报告已保存");}]

  4. 保存报告:

    • 以编程方式:如果您想保存对按钮单击事件的更改并在单击侦听器中调用以下函数,请在您的应用程序中添加一个保存按钮:

      1. 如果要将报告更改保存为新报告

        <块引用>

        function saveReport() {var saveAsParameters = {名称:"};this.report.saveAs(saveAsParameters);}

      2. 如果要将报告更改保存在同一报告中

        <块引用>

        this.report.save();

    • Power BI 嵌入式体验:

      1. 如果要将报告更改保存为新报告:
        • 点击左上角的文件"下拉菜单 >单击另存为">输入您的新报告的名称 >点击保存"
      2. 如果要将报告更改保存在同一报告中:
        • 点击左上角的文件"下拉菜单 >点击保存"

注意:已保存"保存操作完成时触发事件并返回 Json 对象 包含新的 reportId、报告名称、旧的 reportId(如果有)以及操作是 saveAs 还是 save.然后就可以使用这个newReportId生成embed url和embed token来嵌入报表并获取报表的实例.

您可以参考GitHub wiki 创建新报告.

Microsoft 文档.

I am using power bi embedded package to embed power bi report - https://github.com/microsoft/powerbi-client-react

Report is embedded in the edit mode so user can create or edit the report. Now I have a save button and once the user makes changes to the power bi report, I would like to save the report in the database. Can you tell me how can I trigger the report event. It looks like allowed events of save does not work.

Also, if I have to get instance of the report after user has made changes or created the report, how can I get the instance of the report again to reflect new changes?

<PowerBIEmbed
    embedConfig = {{
        type: 'report',   // Supported types: report, dashboard, tile, visual and qna
        id: '<Report Id>',
        embedUrl: '<Embed Url>',
        accessToken: '<Access Token>',
        tokenType: models.TokenType.Embed,
        viewMode: models.ViewMode.Edit,
        settings: {
            panes: {
                filters: {
                    expanded: false,
                    visible: false
                }
            },
            background: models.BackgroundType.Transparent,
        }
    }}

    eventHandlers = { 
        new Map([
            ['loaded', function () {console.log('Report loaded');}],
            ['rendered', function () {console.log('Report rendered');}],
            ['error', function (event) {console.log(event.detail);}]
        ])
    }
        
    cssClassName = { "report-style-class" }

    getEmbeddedComponent = { (embeddedReport) => {
        this.report = embeddedReport as Report;
    }}
/>

Report is being embedded correctly but now after someone has made changes, how do I get the updated report instance again so I can get visuals and store it in the database?

解决方案

Currently, power-client-react does not support creating a fresh report. But, you can edit an existing report and save it as a new report using this library. To do this, you need to implement the following steps:

  1. Generate embed token:

    • If report changes are to be saved as a new report, pass the following JSON body in the generate embed token request:

      {
        "accessLevel": "Edit",
        "allowSaveAs": "true",
      }
      

    • If report changes are to be saved in the same report, pass the following JSON body in the generate embed token request:

      {
        "accessLevel": "Edit",
      }
      

  2. Embed report - add these configs in your embedConfig object:

    viewMode: models.ViewMode.Edit,
    permissions: models.Permissions.All,
    

  3. Handle "saved" event:

    • If report changes are to be saved as a new report, add the following event handler in your eventHandlers map to get the new report Id and then embed the new report to get its instance:

      ['saved', function (event) {
          var newReportId = event.detail.reportObjectId);
      }]
      

    • If report changes are to be saved in the same report, add the following event handler in your eventHandlers map just to make sure the changes have been saved:

      ['saved', function (event) {
          console.log("Report saved");
      }]
      

  4. Save the report:

    • Programmatically: Add a save button in your application if you want to save the changes on button click event and call the following function in the click listener:

      1. If report changes are to be saved as a new report

        function saveReport() {
          var saveAsParameters = {
              name: "<name_of_new_report>"
            };
          this.report.saveAs(saveAsParameters);
        }
        

      2. If report changes are to be saved in the same report

        this.report.save();
        

    • Power BI embedded experience:

      1. If report changes are to be saved as a new report:
        • Click on 'File' dropdown at top-left corner > Click on 'Save as' > Enter the name your new report > Click on 'Save'
      2. If report changes are to be saved in the same report:
        • Click on 'File' dropdown at top-left corner > Click on 'Save'

Note: "saved" event is fired when the save operation is complete and it returns a Json object containing the new reportId, report name, the old reportId (if there was one) and if the operation was saveAs or save. Then you can use this newReportId to generate embed url and embed token to embed the report and get the instance of the report.

You can refer to GitHub wiki to create a fresh report.

Find full article in Microsoft Docs.

这篇关于进行更改后将 Power BI 嵌入式报表保存在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆