Tables Context:
What I need to achieve:
function filterTermeniPachetVacanta(executionContext) {
var formContext = executionContext.getFormContext();
var pachetVacantaId = formContext.getAttribute("pv_pachetvacanta").getValue();
var termeniControl = formContext.getControl("pv_termenisiconditii");
if (!pachetVacantaId) {
console.error("Pachet Vacanta is not selected.");
return;
}
// Fetch categories from the selected Pachet Vacanta
Xrm.WebApi.retrieveRecord("pv_pachetvacanta", pachetVacantaId[0].id, "?$select=pv_categorie").then(
function success(result) {
var categories = result["pv_categorie"];
if (!categories) {
console.error("No categories found or data is not in the expected format.");
return;
}
// Ensure categories is an array
categories = Array.isArray(categories) ? categories : [categories];
console.log("Retrieved categories:", categories);
// Generate filter XML with each category in a separate <condition> tag using the eq operator
var categoryConditions = categories.map(function (category) {
return "<condition attribute='pv_categorie' operator='eq' value='" + category + "' />";
}).join("");
var filterXml = "<filter type='or'>" + categoryConditions + "</filter>";
console.log("Generated Filter XML for Termeni si Conditii:", filterXml);
// Apply filter to the Termeni si Conditii lookup
if (termeniControl) {
termeniControl.addPreSearch(function () {
termeniControl.addCustomFilter(filterXml);
});
console.log("Filter applied to Termeni si Conditii lookup.");
} else {
console.error("Termeni si Conditii lookup control not found.");
}
},
function (error) {
console.error("Error retrieving Pachet Vacanta categories:", error.message);
}
);
}
function onLoad(executionContext) {
filterTermeniPachetVacanta(executionContext);
}
Here is my error when I have multiple choices added in Pachet Vacanță