web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

D365FO - InventDimCombination always selecting first variant color instead of selected variant

(0) ShareShare
ReportReport
Posted on by 54

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.

Categories:
I have the same question (0)

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.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
11manish Profile Picture

11manish 117

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 76 Super User 2026 Season 1

#3
Martin Dráb Profile Picture

Martin Dráb 58 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans