0

I have a PowerBI report having 5 different pages. The code below helps me to set a desired page as the default page when the web page I embedded the PowerBI report comes up to my screen.

var report = powerbi.embed(reportContainer, config); 

report.on('loaded', () => {
   report.getPages().then(pages => pages[3].setActive()); 
});

Two questions I have at this point that I couldn't find answers:

1- How can I set a page as default by using its exact name instead of the array number? I need to do something like: pages => pages['Overall Summary'].setActive();

2- Is there a way to receive the pages on C#, or pass the ones I am getting to the C#? The reason I ask this that I want to hide some pages based on the user logged in.

Any advice would be appreciated. Thanks!

EDIT: By saying pagename, I meant the tab names at the bottom of the powerBI report, each page has a different name as to been: enter image description here

Eray Balkanli
  • 7,752
  • 11
  • 48
  • 82
  • Are you asking how to get report names in C# for #2? If so you need to use the .net sdk: https://learn.microsoft.com/en-us/power-bi/developer/embed-sample-for-your-organization. This will allow you to GetReports and you can then process each value from the return. – JonH Jan 11 '19 at 19:19
  • With this page, I managed to receive the report, yes. But each report includes a number of pages, like an excel file includes separate tabs, and each page has a different name itself. I managed to receive those page names (5 separate names for my case) in JS, i need another way to get them on C# or direct them from JS to C# @JonH – Eray Balkanli Jan 11 '19 at 19:27
  • Sorry I am not following what you want. The .net SDK that I linked above shows exactly that. – JonH Jan 11 '19 at 19:39
  • @JonH I edited my question by adding a screenshot. Via the page you have stated, I managed to receive the title of the report, but I need the titles of the each page of the report. I couldn't see where exactly we are doing this in the link you sent, if it is included, sorry. – Eray Balkanli Jan 11 '19 at 19:44
  • DatasetID, EmbedUrl, WebUrl, Id,Name are the available properties of a report object. Here reportname is available, but I need to reach the pages and get the names of the each page of the report. @JonH – Eray Balkanli Jan 11 '19 at 19:48
  • Do you want to load a specific report by its tab name? For instance, you'd like the report to open with the "R Visuals" tab selected? – JonH Jan 11 '19 at 20:22
  • Yes, exactly! But I need the user to specify it. So the default tab can be editable. That's why I can't set a static one. I should get the page titles at some point, match it what user entered and set it to active by coding js or c#. @JonH – Eray Balkanli Jan 11 '19 at 20:43

2 Answers2

0

1- Unfortunately the "page" object is not holding an ID or INDEX property currently. You can see all the properties by doing console.log(page); However, we have the "displayname" property, and this is what I was looking for. All we need to do is to save the pages in an array object and use a counter to have the index of that while looping. Check the code below that handles this issue:

report.on('loaded', () => {
   report.getPages().then(function (pages) 
      pages.forEach(function(page) { pageArray.push(page);}); 
      var i = 0;
      while (i < pageArray.length) { 
        if (pageArray[i].displayName == \"" + activePageSet + "\") { pages[i].setActive(); } 
        i = i + 1;
      } 
   });
});

2- There is no way to reach the pages in the C# currently, only JS works. To hide any page, you can go to PowerBI Report Editor, simply right click any page and click "Hide Page" option. For such cases you need to hide/unhide pages based on a user or a group, this link has a great solution for that: https://community.powerbi.com/t5/Developer/Power-BI-Embed-Page-Menu-as-List-View/td-p/174938

Eray Balkanli
  • 7,752
  • 11
  • 48
  • 82
0

For

  1. Can you think about updating the embed config to provide the page name in the config. So you'll not have to update it after calling embed. This will load the report with the provided page as the Active Page:

    var config = {
        ...
        pageName: 'Overall Summary'
    };
    

    Reference: https://github.com/Microsoft/PowerBI-JavaScript/wiki/Embed-Configuration-Details

  2. Not sure about C#, In JS Client, Power BI returns the pages object which has all the information about pages. You'll not be able to modify the navigation pane without editing the source report which will update it for all the users. So for hiding pages based on users, you can add your own navigation pane and then only display the restricted set of pages there. You can then update the active page to change to that page.

For this you can follow the community link Erray has shared.