Power BI webpart not visible when adding it with OfficeDevPnP
-
25-01-2021 - |
Question
I am creating a console app that will create sitepages with certain webparts in it.
To Manage this I am using OfficeDevPnP and how I do it is described in the text below.
The issue here is that the sitepage is created successfully with all my webparts in it except the PowerBi webpart. The Power BI webpart is created and the url Property is set to the url I specefied but I can't see the webpart unless I enter edit mode once again and republish the page.
I am creating the sitepage in the following steps:
- Getting context of the SiteCollection that I am targeting
- Reading a Json file defining my pages and webparts that is going to be created
- Creating a sitePage with
context.Web.AddClientSidePage(page.SitePageName, false)
Attaching my webparts to the sitepage in the following steps
- Getting all components and selecting the Power BI component
page.AvailableClientSideComponents()
- Creating a ClientSideWebPart with the Power BI component
new ClientSideWebPart(pwerBiComponent)
- Adding url to my Power BI report Properties
JToken jTokenVal = "https://myPowerbiUrl.justatesturl"; powerBiWebpart.Properties.Add("currentReportEmbedCode", jTokenVal);
- Adding webpart to pagecontrol
page.AddControl(powerBiWebpart);
- Getting all components and selecting the Power BI component
Saving and publishing the page
page.Save(); page.Publish();
So my question here is why isn't the webpart visible until I edit the page?
Solution
Because the webpart needs a set a configuration, which you provide during editing the page, rather you should add the webpart to the page with preconfigured set of properties. That will make your webpart appear directly