I am working on D365FO customization in InventJournalMovement form.
I am using the standard ItemId field in InventJournalTrans.
Requirement:
When user selects ItemId, I want to auto-fill Color, Size, Style, and Config dimensions.
Current issue:
The code always fills the FIRST available variant/dimension combination for the item instead of the actual variant/color selected by the user.
Example:
If item has variants:
-
Red / Small
-
Blue / Medium
-
Green / Large
The code always auto-fills the first combination (for example Red/Small).
Current code:
[FormDataFieldEventHandler(
formDataFieldStr(InventJournalMovement, InventJournalTrans, ItemId),
FormDataFieldEventType::Modified)]
public static void ItemId_OnModified(FormDataObject sender, FormDataFieldEventArgs e)
{
FormDataSource inventJournalTrans_ds;
InventJournalTrans inventJournalTrans;
InventDimCombination inventDimCombination;
InventDim inventDim, currentInventDim;
FormDataSource inventDim_ds;
FormRun formRun;
formRun = sender.datasource().formRun();
inventJournalTrans_ds = sender.datasource();
inventJournalTrans = inventJournalTrans_ds.cursor();
inventDim_ds = formRun.dataSource(tableStr(InventDim));
currentInventDim = inventDim_ds.cursor();
if (inventJournalTrans.ItemId)
{
select firstOnly inventDimCombination
where inventDimCombination.ItemId == inventJournalTrans.ItemId;
if (inventDimCombination.RecId)
{
inventDim = InventDim::find(inventDimCombination.InventDimId);
currentInventDim.configId = inventDim.configId;
currentInventDim.InventColorId = inventDim.InventColorId;
currentInventDim.InventSizeId = inventDim.InventSizeId;
currentInventDim.InventStyleId = inventDim.InventStyleId;
inventJournalTrans.InventDimId =
InventDim::findOrCreate(currentInventDim).InventDimId;
}
}
}
In this image, if I select the Red variant, the system auto-fills Blue instead of Red.
The code is always selecting the first available InventDimCombination record for the item:
I understand the issue is caused by:
select firstOnly inventDimCombination
where inventDimCombination.ItemId == inventJournalTrans.ItemId;
because it always fetches the first available variant.
Question:
What is the standard approach in D365FO to populate the correct selected Color/Size/Style for the item instead of the first variant?
Should this logic be handled differently using standard variant framework or InventDimCtrl classes?
Any guidance or best practice would be appreciated.

Report
All responses (
Answers (