[ExtensionOf(formDataFieldStr(PurchTable, PurchLine, PurchPrice))] final class PurchTable_PurchLinePurchPrice_Extension { public void modified() { FormDataObject formDataObject = any2Object(this) as FormDataObject; FormDataSource formDataSource = formDataObject.datasource(); PurchLine purchLine; next modified(); purchLine = formDataSource.cursor(); if (purchLine) { // Log current inventDimId info(strFmt("Before update: InventDimId = %1", purchLine.InventDimId)); // Call the PurchLine method that updates batch number (should update purchLine.InventDimId) purchLine.updateBatchNumber(); // Ensure the PurchLine buffer's inventDim values are applied purchLine.modifyInventDim(purchLine.inventDim(), fieldNum(InventDim, InventBatchId), false); // Option B: explicitly set the InventDim datasource on the form to the updated invent dim record InventDim invDimRec = InventDim::find(purchLine.InventDimId); FormRun formRun = formDataSource.formRun(); FormDataSource inventDimDs; if (formRun && invDimRec) { // Get the InventDim datasource from the PurchTable form inventDimDs = formRun.dataSource(formDataSourceStr(PurchTable, InventDim)); if (inventDimDs) { // Set the datasource record to the found InventDim, make it current and refresh UI inventDimDs.setRecord(invDimRec); inventDimDs.setCurrent(); inventDimDs.refresh(); } // Also refresh the PurchLine datasource so UI shows any other updated fields formDataSource.refresh(); } info(strFmt("After update: InventDimId = %1", purchLine.InventDimId)); } } }
[ExtensionOf(tableStr(PurchLine))] public final class PurchLine_Extension { public boolean shouldRetrieveBatchNumber() { PurchParameters purchParameters = PurchParameters::find(); PurchTable purchTable = this.purchTable(); return purchParameters.RetrieveBatchNum == NoYes::Yes && (purchTable.PurchaseType == PurchaseType::ReturnItem || purchTable.PurchaseType == PurchaseType::Purch) && this.LineAmount < 0; } public void updateBatchNumber() { EcoResTrackingDimensionGroupItem ecoResTrackingDimensionGroupItem; EcoResTrackingDimensionGroup ecoResTrackingDimensionGroup; InventTable inventTable; InventNumGroup inventBatchNumGroup; InventDim inventDim; ecoResTrackingDimensionGroupItem = EcoResTrackingDimensionGroupItem::findByItem(this.DataAreaId,this.ItemId); inventTable = InventTable::find(this.ItemId); inventBatchNumGroup = InventNumGroup::find(inventTable.BatchNumGroupId); inventDim = this.inventDim(); select firstonly ecoResTrackingDimensionGroup where ecoResTrackingDimensionGroup.RecId == ecoResTrackingDimensionGroupItem.TrackingDimensionGroup; if(this.shouldRetrieveBatchNumber() && inventBatchNumGroup.FixedValue == NoYes::Yes && inventBatchNumGroup.InclExpectedDate == NoYes::No && ecoResTrackingDimensionGroup.Name == 'Batch') { inventDim.inventBatchId = inventTable.BatchNumGroupId; // Find or create the dimension combination this.InventDimId = InventDim::findOrCreate(inventDim).InventDimId; ///this.modifyInventDim(inventDim,fieldNum(InventDim, inventBatchId), false); } } }
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Martin Dráb 719 Most Valuable Professional
André Arnaud de Cal... 650 Super User 2025 Season 2
CU05031448-0 536