const subgrid = formContext.getControl("PreviousPriceGrid");
// Define filtered FetchXML
const fetchXml = `
<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='cr123_pricechange'>
<attribute name='cr123_productid'/>
<attribute name='cr123_productname'/>
<attribute name='cr123_effectivefrom'/>
<attribute name='cr123_newprice'/>
<order attribute='cr123_efffectivefrom' descending='true'/>
<filter type='and'>
<condition attribute='cr123_productid' operator='eq' value='${productId}'/>
</filter>
</entity>
</fetch>`;
console.log("Applying custom view to subgrid...");
try {
if (!subgrid) {
console.log("Subgrid 'PreviousPriceGrid' not found.");
return;
}
subgrid.setFilterXml(fetchXml);
subgrid.refresh(); // Refresh to apply the filter
console.log("Filter applied successfully.");
} catch (e) {
console.error("Error applying filter:", e);
}