function filterPickupSubgrid(executionContext) {
var formContext = executionContext.getFormContext();
var lookupField = formContext.getAttribute("ppt_sitename"); // Replace with your lookup field name
var subgridName = "subgrid_pickupdata"; // Replace with your subgrid name
var lookupValue = lookupField.getValue();
if (lookupValue != null && lookupValue.length > 0) {
var lookupId = lookupValue[0].id;
var entityName = lookupValue[0].entityType;
var fetchXml = `<fetch version='1.0' mapping='logical'>
<entity name='ppt_pickupdata'>
<attribute name='ppt_pickupdataid' />
<filter type='and'>
<condition attribute='ppt_pickupdata_SiteName_account' operator='eq' uitype='${entityName}' value='${lookupId}' />
</filter>
</entity>
</fetch>`;
formContext.getControl(subgridName).setFilterXml(fetchXml);
formContext.getControl(subgridName).refresh();
} else {
// If the lookup field is empty, show all records in the subgrid
var fetchXmlAll = `<fetch version='1.0' mapping='logical'><entity name='ppt_pickupdata'><attribute name='ppt_pickupdataid' /></entity></fetch>`;
formContext.getControl(subgridName).setFilterXml(fetchXmlAll);
formContext.getControl(subgridName).refresh();
}
}