Closed LemonGeu closed 6 years ago
I have the same issue.
Regards, Christina
Hi Lemon and Christina,
Can you tell me:
Hello taarskog,
thank you for your quick response.
Thanks Christina,
I am able to reproduce the issue. Will investigate and hopefully have an update later today or sometime this Weekend.
-Trond
Hello Trond,
First case
Seconde case
Looking forward to your response. Thanks alot!
Lemon
Hi Taarskog,
Here to report the same issue.
Issue reproduceavle in Chrome > latest , but not Firefox.
Error is the same as above, except this element “Cannot read property: ‘isDeprecated’ of undefined could not be cloned”.
Error occurs at the setting filters step.
Many thanks, James
Looks like the Power BI team may have introduced a bug (or "feature" ;-))
In my tests I initially tried to set a filter on the event pagechanged. As you I also got the promise rejection.
The fix that worked for me was to add an empty call to setFilters on the event loaded. The call does not need to contain an actual filter but it seems to initialize objects that are required when setting filters on pageChanged.
Appreciate if you can help verify by adding the following to your code (adjust names etc. to match your code):
Samples.Filters.filterOnUser = function(report) {
report.on("loaded", function(event) {
report.setFilters([]);
... Original code triggering on pageChanged ...
});
}
UPDATE (after posting): Added empty array on call to setFilters. Se details a few comments down
Hello Trond,
I tried to setFilters on loaded event. But for the v1.0 and the v1.1.0 version I get same errors. Also if I change a page afterwards I get the first error message again since the page is already loaded at that point.
What should I change in the script?
Lemon
Hi Lemon,
Did you clear the cache and increase the script file version in the config file (e.g. ?ver=2
)? Suggest you also add a console.log
right after setting the empty filter to verify that you are executing the most recent code changes.
-Trond
Hi Trond,
I did clear cache + tried incognito browser. Also from what I can see the '?ver=x' isn't needed at this moment. But I did use it now with still no succes. I get "empty filter" in the console log written by console.log.
Lemon
Hi Lemon,
Thank you for testing. Unfortunately I made a mistake Yesterday when I provided the code above. The empty call to setFilters require an empty array: report.setFilters([]);
.
Though I believe using report.removeFilters();
may be a better function to use. Both approaches are working in my environments.
-Trond
Hi Trond,
removeFilters() did indeed fix the errors. The scripts loads and triggers the pageChanged.
At this moment it doesn't filter my first page (that is not changed) before it did it. I didn't manage to get it working on page load yet. Do you have any idea how to trigger to get my first loaded page filtered aswell?
Anyways alot of thanks for the quick support!
Lemon
Hello Trond,
thank you for your prompt solution. It works by changing the report page, but not on initial load. Before this bug/feature (we will never know) it worked fine. Maybe is there antoherway to trigger it?
Or is there an error in my code?
Samples.Filters.filterOnAccount = function (report) {
report.on("loaded", function(loadedEvent) {
console.log("Report loaded");
console.log("Remove filters on report");
report.removeFilters();
report.on("pageChanged", function(event) {
let page = event.detail.newPage;
console.log(`Page changed to '${page.displayName}' (${page.name})`);
var firma = window.parent.Xrm.Page.data.entity.getId();
firma = firma.replace('{', '').replace('}', '');
console.log("Firma - " + firma);
if (page.displayName === "Produktauswertung" || page.displayName === "Jahresauswertung") {
const filter = {
$schema: "http://powerbi.com/product/schema#basic",
target: {
table: "accounts",
column: "accountid"
},
operator: "In",
values: [firma]
};
page.setFilters([filter]);
}
});
});
}
Thank you so much for your help.
Christina
Lemon and Christina,
Thanks for providing feedback. Glad to hear it now works.
Regarding setting the initial filter the following seems to work (not sure if it is the right approach though). I'm closing this issue now, but feel free to open another on initial load if my suggestion below does not work.
let filteredSet = false
report.on('rendered', () => {
if (filteredSet) return;
filteredSet = true;
report.getPages()
.then(function (pages) {
// Retrieve active page.
var activePage = pages.find(function(page) {
return page.isActive
});
activePage.setFilters([filter])
.then(function () {
console.log("Page filter was set.");
})
.catch(function (errors) {
console.error(errors);
});
})
.catch(function (errors) {
console.error(errors);
});
});
Hello Trond,
thanks a lot for you code. Everything is working fine now. It's fantastic to get such a great support of an amazing product.
Christina
Hi Trond and Christina,
I have the same issue (filtering on initial load).
Where have I to insert the code:
let filteredSet = false
report.on('rendered', () => {
if (filteredSet) return;
filteredSet = true;
report.getPages()
.then(function (pages) {
// Retrieve active page.
var activePage = pages.find(function(page) {
return page.isActive
});
activePage.setFilters([filter])
.then(function () {
console.log("Page filter was set.");
})
.catch(function (errors) {
console.error(errors);
});
})
.catch(function (errors) {
console.error(errors);
});
});
in my JS:
window.Samples = window.Samples || {};
Samples.Filters = Samples.Filters || {};
Samples.Filters.filterOnAccount = function (report) {
report.on("loaded", function (loadedEvent) {
report.removeFilters(); // For some reason this needs to be done before setting page filters (August 2018)
report.on("pageChanged", function(event) {
let page = event.detail.newPage;
console.log(`Page changed to '${page.displayName}' (${page.name})`);
{
var accId = window.parent.Xrm.Page.data.entity.getId();
accId = accId.replace('{','').replace('}','');
const filter = {
$schema: "http://powerbi.com/product/schema#basic",
target: {
table: "accounts",
column: "accountid"
},
operator: "In",
values: [accId]
};
page.setFilters([filter]);
}
});
});
}
Thanks Sergio
Hello,
I'm using your powerbi viewer but since a couple of days I get this error message. I'm use a javascript to filter out a specific account. I can still see the report but it doesn't get filtered anymore.
Any solutions?
Kind regards,
Lemon