Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreWe've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
Hello, so I am trying to add a filter after the report loads but it gives me this error:
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'Add')
I got the code I am using from the offical documentation from Here , why is it not recognising the Add property?
Here is my embed code for clarification, any help is much appreciated:
<script type="text/javascript">
$(document).ready(async function () {
var accessToken = "@Model.EmbedToken.Token";
// Read embed URL from Model
var embedUrl = "@Html.Raw(Model.EmbedUrl)";
// Read report Id from Model
var embedReportId = "@Model.Id";
var embedUserName = "@Model.Username";
// Get models. models contains enums that can be used.
var models = window['powerbi-client'].models;
// Embed configuration used to describe the what and how to embed.
// This object is used when calling powerbi.embed.
// This also includes settings and options such as filters.
// You can find more information at https://github.com/Microsoft/PowerBI-JavaScript/wiki/Embed-Configuration-Details.
const userIdFilter = {
$schema: "http://powerbi.com/product/schema#basic",
target: {
table: "reports users",
column: "UserName"
},
operator: "In",
values: [embedUserName],
filterType: models.FilterType.BasicFilter,
requireSingleSelection: true
};
var config = {
type: 'report',
tokenType: models.TokenType.Embed,
accessToken: accessToken,
embedUrl: embedUrl,
id: embedReportId,
permissions: models.Permissions.All,
settings: {
filterPaneEnabled: false,
navContentPaneEnabled: true,
}
};
// Get a reference to the embedded report HTML element
var reportContainer = $('#embedContainer')[0];
if ("@Model.Username" != "") {
$("#RLS").prop('checked', true);
$("#RLSdiv").show();
}
else {
$("#RLS").prop('checked', false);
$("#RLSdiv").hide();
}
if ("@Model.IsEffectiveIdentityRequired.GetValueOrDefault()" == "True") {
$("#noRLSdiv").hide();
$("#RLS").removeAttr("disabled");
$("#RLS").change(function () {
if ($(this).is(":checked")) {
$("#RLSdiv").show(300);
} else {
$("#RLSdiv").hide(200);
}
});
}
else {
$("#noRLSdiv").show();
}
// Embed the report and display it within the div container.
var report = powerbi.embed(reportContainer, config);
report.on('loaded', event => {
//if (embedUserName == "tester")
runUpdate();
});
async function runUpdate() {
console.log("run update?");
await report.updateFilters(models.FiltersOperations.Add, userIdFilter);
}
});
</script>
Hi @SoulsSama,
I think this should be related to the parameter that you used in updatefilters function. If you are not familiar with filter structures, you can try to use getfilter function to get the sample data with default filter structures.
Regards,
Xiaoxin Sheng
Hi @Anonymous
First of all thank you for your suggestion, I tried getFilters function and logged the response, it is working but I don't see how will this solve my problem in here? I have a custom filter and it works normally when I apply it directly inside my config object, the problem is that I want to add the filter when the report is ( on loaded ), in the documentation Add function is written and I just copied the syntax as it is, but the error says that it's undefined, which means that Add property does not exist for FilterOperations method, I hope this clarify my problem, any more tips and recommendation would be much appreciated.
Here is a screenshot for the code line that I'm trying to implement:
Best Regards,
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |