I was working on a customization to auto-fill the Product Dimensions, like Configuration, color, style, and size, when the itemId is selected in the EcoResProductSearchLookup, other fields, like product name, etc., automatically fill. But I'm facing an issue with auto-filling. I tried using COC on the SalesLine table, Event Handler on EcoResProductSearchLookup, and COC on the EcoResProductSearchLookup form, but none of them are working as expected. So here is the code snippet that I have written in the EcoResProductSearchLookup form extension on closeSelect(), which triggers when I try to select the ItemId:
public void closeSelect(str _selectString)
{
FormRun callerFormLocal;
InventDistinctProduct product;
SalesLine salesLine;
InventDim inventDim;
InventDim defaultInventDim;
InventDimCombination inventDimCombination;
next closeSelect(_selectString);
callerFormLocal = this.args().caller();
if (callerFormLocal)
{
product = InventDistinctProduct::findByProduct(inventDistinctProductExpanded.Product);
callerFormLocal.setProductFromLookup(product);
FormDataSource salesLineDs = callerFormLocal.dataSource(formDataSourceStr(SalesTable, SalesLine));
if (salesLineDs)
{
salesLine = salesLineDs.cursor();
if (salesLine && salesLine.SalesType == SalesType::ReturnItem)
{
select firstOnly inventDimCombination
where inventDimCombination.ItemId == salesLine.ItemId;
if (inventDimCombination)
{
defaultInventDim = InventDim::find(inventDimCombination.InventDimId);
inventDim.clear();
inventDim.configId = defaultInventDim.configId;
inventDim.InventSizeId = defaultInventDim.InventSizeId;
inventDim.InventColorId = defaultInventDim.InventColorId;
inventDim.InventStyleId = defaultInventDim.InventStyleId;
inventDim = InventDim::findOrCreate(inventDim);
salesLine.InventDimId = inventDim.InventDimId;
salesLine.doUpdate();
salesLineDs.refresh();
}
}
}
}
}