taarskog / crm-powerbi-viewer

Embed tiles and reports from Power BI into Dynamics CRM Forms and Dashboards.
http://crm-powerbi-viewer.heiigjen.com/
MIT License
27 stars 9 forks source link

Report on dashboard not filtering #45

Closed Aj-Nunez closed 5 years ago

Aj-Nunez commented 5 years ago

Describe the bug I've embedded a report onto a system dashboard and expected to be able to filter the same as it is done on the different forms(accounts, opportunity, etc). However the report is not filtering. Developer tools is no help either because the script is never called. I'm using a treemap visual on the report.

Screenshots

Samples.Filters.filterUser = function (report) {
    debugger;
    report.on("pageChanged", function (event) {
        let page = event.detail.newPage;
        console.log(`Page changed to '${page.displayName}' (${page.name})`);

        if (page.displayName === "Page 1") {
            var user = window.parent.Xrm.Page.context.getUserId();
            user = user.replace('{', '').replace('}', '');
            const filter = {
                $schema: "http://powerbi.com/product/schema#basic",
                target: {
                    table: "Teams",
                    column: "_administratorid_value"
                },
                operator: "In",
                values: [user]
            };

            page.setFilters([filter]);
        }
    });
}`

Environment (please complete the following information):

Additional context Debugger does not work, the script is not called. All other filters used on forms work. I've made sure the custom control is added to the web resource on the dashboard. JScript was added to array.

taarskog commented 5 years ago

Can you share:

  1. The "Custom parameter (data)" from the dashboard web resource
  2. Your config-file
Aj-Nunez commented 5 years ago

Sorry for the delayed response, I have tried a new script/method so that's why the method being called is different than what's provided above, but again still no luck. Debugger never reaches any breakpoint. I'm not sure what I'm missing because like I mentioned this has been a great resource and works awesome when adding reports to forms. Any insights to this is greatly appreciated. Thanks,

  1. Custom Parameter capture

type=report&id=037b4bec-280e-4bd6-8c68-aa6d86403024&pageName=&showFilterPane=true&showNavPane=false&customFn=filterDashboard

  1. `var customConfig = { /////////////////////////////// // ITEMS THAT MUST BE CHANGED ///////////////////////////////

    // See documentation on how to register the application in Azure AD and get a client id (remember to enclose with quotes - see sample). // Sample: auth_client_id: "12345678-1234-abcd-1234-11aabb22cc", auth_client_id: "5f4e71ee-0e40-4c27-899f-b0ac05032759",

    /////////////////////////////////////////// // CAN USUALLY BE LEFT UNCHANGED // (unless specified in the documentation) ///////////////////////////////////////////

    // How to perform authentication - valid values are "inline" or "popup". Default is "inline" (rember to enclose with quotes). // You should typically use "inline" on Dynamics 365 Online with users located in your Azure AD and "popup" when on-premise (might also be required if you have invited external parties to your Azure AD). auth_mode: null,

    // Auto-refresh access - may cause page reload if token cannot be updated silently [valid values are true or false]. Default is true. auto_refresh_token: null,

    // Where to cache tokens. Valid values are 'sessionStorage' and 'localStorage'. Default is 'sessionStorage'. auth_cache_location: null,

    // Logging of Adal authentication process [Valid values are 0-3] (0=ERROR, 1=WARNING, 2=INFO, 3=VERBOSE). Default is 0. auth_log_level: null,

    // Log level for Power BI Viewer [Valid values are 0-3] (0=ERROR, 1=WARNING, 2=INFO, 3=DEBUG). Default is 0. // (is not affected by and does not affect auth_log_level) log_level: null,

    // Array of custom scripts to load. Functions in these scripts can be referenced for report filtering etc. // Sample: custom_scripts: ["../../newmyfilter?ver=1", "../../demo/powerbi/filters/account.js?ver=1"] custom_scripts: ["https://im360poc.crm.dynamics.com//WebResources/im360_opportunity_pbiFilter.js?ver=1", "https://im360poc.crm.dynamics.com//WebResources/im360_im360poc_quoteSection.js?ver=1", "https://im360poc.crm.dynamics.com//WebResources/im360_im360poc_accountsection.js?ver=1", "https://im360poc.crm.dynamics.com//WebResources/im360_dashboardTreeMap.js?ver=2"], };`

taarskog commented 5 years ago

I've tested this now in my environment and it works with config as your screenshot and with treemap as visual. Can you also share your updated code so we can see the code corresponding to the config you posted above?

Aj-Nunez commented 5 years ago

@taarskog This is resolved! Steps I took to solve issue: created a new web resource the same as above and then added this to the conifg resource with the new URL and then to my dashboard. Not sure why this worked (maybe something with my machines cache?) but nonetheless it works as expected. This is a fantastic solution thank you @taarskog for your assistance