在powerbi javascript api中加载分页报告时无法传递自定义参数



目标:在powerbi-api javascript的帮助下,将分页报告加载到几乎没有参数的网页中。

分页报表URL:https://app.powerbi.com/groups/workspaceId/rdlreports/reportId?ctid=something&rp:CustomerID=something&rp:ContractID=某种

我可以加载报告,但无法传递参数,因此报告加载为空。

与powerbi报表一样,分页报表不支持report.getFilters((,就像powerbi嵌入的报表一样。

我介绍了这些文档,但找不到任何帮助。。。

https://learn.microsoft.com/en-us/power-bi/paginated-reports-parametershttps://learn.microsoft.com/en-us/power-bi/developer/paginated-reports-row-level-security#passing-使用嵌入令牌的配置参数https://learn.microsoft.com/en-us/power-bi/developer/embed-paginated-reports-customers

这就是我如何获得powerbi报告,然后将其嵌入网页:

[HttpGet]
[Route("AccessToken")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<ActionResult> GetEmbeddedAccessTokenAsync(string reportType)
{            
Guid currentReportId = getCurrentReportId(reportType); //private method which gets the report guid
using (var client = await GetPowerBIClientAsync())
{                
var report = await client.Reports.GetReportInGroupAsync(_powerBiWorkspaceId, currentReportId);


var generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: TokenAccessLevel.View);
var tokenResponse = await client.Reports.GenerateTokenInGroupAsync(_powerBiWorkspaceId, report.Id, generateTokenRequestParameters);

return new OkObjectResult(JsonSerializer.Serialize(new { EmbedUrl = report.EmbedUrl, AccessToken = tokenResponse.Token, WorkspaceId = _powerBiWorkspaceId, ReportId = report.Id, Expires = tokenResponse.Expiration }));
}
}


let token = await this.http.get(this.url + 'api/PowerBi/AccessToken?reportType=' + this.reportType, { params: {}, responseType: 'text', withCredentials: true }).toPromise();
let tokenObject = JSON.parse(token);
let reportContainer = document.getElementById('kpi-report-container');
this.powerbi.bootstrap(reportContainer, config);
let report: Report = <Report>(this.powerbi.embed(reportContainer, config));

// Report.off removes a given event handler if it exists.        
report.off("loaded");
let self = this;
// Report.on will add an event handler which prints to Log window.
report.on("loaded", function () {
self.SelectedReportId(self.reportId);
report.updateSettings({
bookmarksPaneEnabled: false,
filterPaneEnabled: true
});
// Set token expiration listener
self.SetTokenExpirationListener(tokenObject.Expires,
2, /*minutes before expiration*/
tokenObject.ReportId,
tokenObject.WorkspaceId);
});

我们可以通过将URL参数与嵌入URL连接,将URL参数传递到嵌入的分页报告中。

例如:如果我们有一个名为";销售人员";其值之一为"0";Brownie";,那么我们可以通过将分页报告连接到报告配置中的报告嵌入URL中来过滤该报告:embedUrl+"&rp:Salespencer=Brownie";

上面的embedUrl将根据给定的参数过滤嵌入的分页报告。

您可以参考此博客链接了解更多信息。

最新更新