目标:在powerbi api javascript的帮助下,将分页报告加载到参数很少的网页中。
我可以加载报告但无法传递参数 - 因此报告加载为空白。
与 powerbi 报表不同,分页报表不支持像 powerBi 嵌入式报表那样的 report.getFilters()。
我参考了这些文档-但找不到任何帮助...
https://docs.microsoft.com/en-us/power-bi/paginated-reports-parameters https://docs.microsoft.com/en-us/power-bi/developer/paginated-reports-row-level -security#passing-the-configured-parameter-using-the-embed-token https://docs.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);
});