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 :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Auto-filling of Product dimensions when ItemId is selected in the EcoResProductSearchLookup

(0) ShareShare
ReportReport
Posted on by 60
Hello Community,
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();
                    }
                }
            }
        }
    }
Categories:
I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    239,452 Most Valuable Professional on at
    Moved from Integration, Dataverse, and general topics forum to Finance | Project Operations, Human Resources, AX, GP, SL forum.
     
    Doing it in EcoResProductSearchLookup isn't correct, because it's purpose is creating a lookup, not initializing some other records. Also, it's
    generic logic used from many places (such as purchase agreements); putting there code specific to SalesLine would be another bug in the architecture.
     
    Another bug is that you're saving the record, which you mustn't do at this point, and you bypass validateWrite() and update(), therefore your code would cause data corruption. These are critical things that you must pay more attention to.
     
    It seems that you're interested in the situation when EcoResProductSearchLookup is called from SalesTable form. In that case, what you need is its updateProductDimensions() method, which is called after selecting an item from the lookup. It's called with InventDim record from the lookup, but you can modify the data if needed.
  • Subra Profile Picture
    466 on at
    Could you please let me know what is the issue you are facing, either you are not getting the values or it's getting the incorrect values?
     
  • Suggested answer
    Deepak Agarwal Profile Picture
    8,801 on at
    You need to add more details in your question like which process you are using, which form, whats default behavviur and whats you want to change within that. 
     
    Generally product dimention drived from product master and followed by further logic on individual froms likes Sales order and Purchase order. You may also need to debug the respective process, if anything overriding the dimension at later point of time. 

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 622

#2
André Arnaud de Calavon Profile Picture

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

#3
CP04-islander Profile Picture

CP04-islander 430

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans