0
I have a user name logging into the Web Application.
I am using HTML, CSS, JavaScript and ASP.NET webform to run the Web Application with Power BI embedded reports.
I am trying to code to pass Server Name and Database name based on the user logged in to Power BI embedded config.
How to pass server name and database name to Power BI Embedded config?
Tried to test the application flow with Import Data Sets using following things, but the Power BI Report is not getting loaded in HTML div element. Its giving "Power BI Loading logo" in the embed div and then showing message as "Power BI content is not available"
Application Flow:
-
Power BI workspace has One Report and Two Datasets
-
Following is the Token generation code in .NET
// Generate an embed token and populate embed variables
using (var client = new PowerBIClient(new Uri(Configurations.ApiUrl), Authentication.GetTokenCredentials()))
//using (var client = new PowerBIClient(new Uri(Configurations.ApiUrl), Authentication.m_tokenCredentials))
{
var report = client.Reports.GetReportInGroup(new Guid(Configurations.WorkspaceId), new Guid(ddlReport.SelectedValue));
var rls = new EffectiveIdentity(username: appLoginUserName, new List<string> { userDatasetId.ToString() });
// Effective Identity
var rolesList = new List<string>();
rolesList.Add("Tenant");
rls.Roles = rolesList;
// Create list of datasets
var v2DatasetID = new List<Guid>();
v2DatasetID.Add(userDatasetId);
// Create list of Effective Identities
var v2rls = new List<EffectiveIdentity>();
v2rls.Add(rls);
// Create a request for getting Embed token
// This method works only with new Power BI V2 workspace experience
var tokenRequest = new GenerateTokenRequestV2(
reports: new List<GenerateTokenRequestV2Report>() { new GenerateTokenRequestV2Report(report.Id) },
datasets: v2DatasetID.Select(datasetId => new GenerateTokenRequestV2Dataset(datasetId.ToString())).ToList(),
identities: v2rls,
targetWorkspaces: null
);
// Generate Embed token
var getToken = client.EmbedToken.GenerateToken(tokenRequest);
// Populate embed variables (to be passed client-side)
//embedToken = tokenResponse.Token;
embedToken = getToken.ToString();
embedUrl = report.EmbedUrl;
reportId = report.Id;
}
- Following is the Power BI embed configuration with dynamic dataset:
<script>
// Read embed token
var embedToken = "<% =this.embedToken %>";
// Read embed URL
var embedUrl = "<% = this.embedUrl %>";
// Read report Id
var reportId = "<% = this.reportId %>";
// Read dataset Id
var userDatasetId = "<% = this.userDatasetId %>";
// Get models (models contains enums)
var models = window['powerbi-client'].models;
// Embed configuration is used to describe what and how to embed
// This object is used when calling powerbi.embed
// It can also includes settings and options such as filters
var config = {
type: 'report',
tokenType: models.TokenType.Embed,
accessToken: embedToken,
embedUrl: embedUrl,
id: reportId,
datasetId: userDatasetId, // The dataset id that you want the report to use
settings: {
filterPaneEnabled: true,
navContentPaneEnabled: true,
extensions: [
{
command: {
name: "cmdShowValue",
title: "Show Value in MessageBox",
selector: {
$schema: "http://powerbi.com/product/schema#visualSelector",
visualName: "VisualContainer7" // Sales and Avg Price by Month visual
},
extend: {
visualContextMenu: {
title: "Show Value in MessageBox"
}
}
}
}
]
}
};
// Embed the report within the div element
var report = powerbi.embed(embedDiv, config);
</script>