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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Facing an issue while updating the invent

(0) ShareShare
ReportReport
Posted on by 30
While performing the registration for the return order line in X++, I am facing an Update Conflict exception when passing the disposition code '41,51 and 61' at the line inventTransWMS_Register.updateInvent(salesLine);

This is the actual code:
 public void inventoryRegistration(SalesTable _salesTable,str _dispositionCode)
 {
     Integer                                 lastRec = 0;
     SalesId                                 oldSalesId;
     inventTrans                             inventTrans;
     SalesFormLetter                         salesFormLetter;
     inventTransOrigin                       inventTransOrigin;
     TradeOrderLineRegister                  tradeOrderlineRegister;
     SalesReturnOrderLineRegister            salesReturnOrderLineRegister;
     InventTransWMS_Register                 inventTransWMS_register;
     TmpInventTransWMS                       TmpInventTransWMS;
     ReturnDispositionCode                   returnDispositionCode;
     Description255                          errorMsg;
     SalesLine                               salesLine;
     TmpFrmVirtual                           tmpFrmVirtual;
 
     Args _args = new Args();
 
     try
     {
         ttsBegin;
         while  select forUpdate salesLine
             where _salestable.SalesId  == salesLine.SalesId
             && _salestable.SalesType == SalesType::ReturnItem
         {
             try
             {
                 _args.record(salesLine);
 
                 tradeOrderLineRegister = SalesReturnOrderLineRegister::construct();
                 tradeOrderLineRegister.parmArgs(_args);
                 tradeOrderLineRegister.init();
                 salesReturnOrderLineRegister = tradeOrderLineRegister;
                 salesReturnOrderLineRegister.runPreSuper();
 
                 //update returnDisposioncode
                 select firstOnly DispositionCodeId from returnDispositionCode
                 where returnDispositionCode.DispositionCodeId == _dispositionCode;
                 if(returnDispositionCode.DispositionCodeId)
                 {
                     salesLine.ReturnDispositionCodeId = returnDispositionCode.DispositionCodeId;
                     salesLine.update();
                 }
                 else
                 {
                     throw error("@BASIS_SOCancellation:Error");
                 }
 
                 select firstOnly crossCompany inventTrans
                     join RecId,InventTransId from inventTransOrigin
                     where inventTransOrigin.InventTransId == salesLine.InventTransId
                     && inventTrans.InventTransOrigin == inventTransOrigin.RecId;
                 //inventTrans = InventTrans::findTransId(salesLine.InventTransId);
                 inventTransWMS_register = inventTransWMS_register::newStandard(tmpInventTransWMS);
                 //inventTransWMS_Register.createFromInventTrans(inventTrans, inventTrans.inventDim());
                 tmpInventTransWMS.clear();
                 tmpInventTransWMS.initFromInventTrans(inventTrans);
                 tmpInventTransWMS.InventDimId = salesLine.InventDimId;
                 tmpInventTransWMS.ItemId      = salesLine.ItemId;
                 tmpInventTransWMS.LineNum     = salesLine.LineNum;
                 tmpInventTransWMS.insert();
                 inventTransWMS_register.writeTmpInventTransWMS(tmpInventTransWMS, inventTrans, inventTrans.inventDim());
                
                 //inventTransWMS_Register.updateInvent(SalesLine::findRecId(salesLine.RecId));
                 inventTransWMS_Register.updateInvent(salesLine);
                 if(returnDispositionCode.DispositionAction == DispositionAction::ReplaceCredit || 
                     returnDispositionCode.DispositionAction == DispositionAction::ReplaceScrap )
                 {
                     tmpFrmVirtual.TableNum    = tableNum(SalesLine);
                     tmpFrmVirtual.RecordNo    = salesLine.RecId;
                     tmpFrmVirtual.ItemId      = salesLine.ItemId;
                     tmpFrmVirtual.LineNum     = salesLine.LineNum;
                     tmpFrmVirtual.Qty         = salesLine.SalesQty;
                     tmpFrmVirtual.InventDimId = inventTrans.inventDimId;
                     tmpFrmVirtual.SalesId     = salesLine.SalesId;
                     tmpFrmVirtual.insert();
                     ReturnReplaceItemRef::createRefReturnFromTmpFrmVirtual(salesLine.SalesId,salesLine.LineNum,tmpFrmVirtual);
                  
                 }
                 
             }
             catch
             {
                 continue;
             }
         }
         ttsCommit;
     }
     catch
     {
         throw error("@BASIS_SOCancellation:Validation5");
     }
 }
Categories:
I have the same question (0)
  • Martin Dráb Profile Picture
    237,882 Most Valuable Professional on at
    Moved from Integration, Dataverse, and general topics forum. Please ask questions about F&O in F&O forums.
     
    What you need to do next is collection more information about the problem. First of all, you need to know update of which table failed. Getting the exact place where the error is thrown and the stack trace will likely be useful too. It may be SalesLine, but it doesn't have to.
     
    For testing purposes, try calling salesLine.reread() before updateInvent().
  • Martin Dráb Profile Picture
    237,882 Most Valuable Professional on at
    By the way, let me simplify your code (to make it easier to work with both for you and other community members), e.g. most of your variables aren't either needed or used at all. Note that I woukd split your code to several methods, each with its own name and responsibility.
    public void inventoryRegistration(SalesTable _salesTable,str _dispositionCode)
    {
        if (_salesTable.SalesType == SalesType::ReturnItem)
        {
            return;
        }
    
        try
        {
            ttsBegin;
            
            SalesLine salesLine;
            
            while select forUpdate salesLine
                where salesLine.SalesId == _salesTable.SalesId
            {
                try
                {
                    SalesReturnOrderLineRegister tradeOrderLineRegister = SalesReturnOrderLineRegister::construct();
                    
                    Args args = new Args();
                    args.record(salesLine);
                    tradeOrderLineRegister.parmArgs(args);
                    
                    tradeOrderLineRegister.init();
                    tradeOrderLineRegister.runPreSuper();
    
                    //update returnDisposioncode
                    if (ReturnDispositionCode::exist(_dispositionCode))
                    {
                        salesLine.ReturnDispositionCodeId = _dispositionCode;
                        salesLine.update();
                    }
                    else
                    {
                        throw error("@BASIS_SOCancellation:Error");
                    }
    
                    InventTrans inventTrans;
                    InventTransOrigin inventTransOrigin;
                    
                    select firstOnly crossCompany inventTrans
                        exists join inventTransOrigin
                            where inventTransOrigin.RecId == inventTrans.InventTransOrigin
                               && inventTransOrigin.InventTransId == salesLine.InventTransId;
                        
                    InventTransWMS_Register inventTransWMS_Register = InventTransWMS_Register::newStandard(tmpInventTransWMS);
                    
                    TmpInventTransWMS tmpInventTransWMS;
                    tmpInventTransWMS.initFromInventTrans(inventTrans);
                    tmpInventTransWMS.InventDimId = salesLine.InventDimId;
                    tmpInventTransWMS.ItemId      = salesLine.ItemId;
                    tmpInventTransWMS.LineNum     = salesLine.LineNum;
                    tmpInventTransWMS.insert();
                    
                    inventTransWMS_Register.writeTmpInventTransWMS(tmpInventTransWMS, inventTrans, inventTrans.inventDim());
                    inventTransWMS_Register.updateInvent(salesLine);
                    
                    if( returnDispositionCode.DispositionAction == DispositionAction::ReplaceCredit
                      || returnDispositionCode.DispositionAction == DispositionAction::ReplaceScrap)
                    {
                        TmpFrmVirtual tmpFrmVirtual;
                        tmpFrmVirtual.TableNum    = tableNum(SalesLine);
                        tmpFrmVirtual.RecordNo    = salesLine.RecId;
                        tmpFrmVirtual.ItemId      = salesLine.ItemId;
                        tmpFrmVirtual.LineNum     = salesLine.LineNum;
                        tmpFrmVirtual.Qty         = salesLine.SalesQty;
                        tmpFrmVirtual.InventDimId = inventTrans.inventDimId;
                        tmpFrmVirtual.SalesId     = salesLine.SalesId;
                        tmpFrmVirtual.insert();
                        
                        ReturnReplaceItemRef::createRefReturnFromTmpFrmVirtual(salesLine.SalesId, salesLine.LineNum, tmpFrmVirtual);
                    }
                    
                }
                catch
                {
                    continue;
                }
            }
            ttsCommit;
        }
        catch
        {
            throw error("@BASIS_SOCancellation:Validation5");
        }
    }
  • CU18032322-0 Profile Picture
    30 on at

      Finally, it is going into the SysExtensionSerializerMap class where the postUpdate() method is called. Inside that, there is a condition if (currentExtensionTable.RecVersion != extensionTableToUpdate.RecVersion) , which is getting satisfied and causing the UpdateConflict exception.

    And this is a standard SysExtensionSerializerMap class and it's causing an issue.

  • Martin Dráb Profile Picture
    237,882 Most Valuable Professional on at
    Which table is it about? In the debugger, you can see the actual data type of currentExtensionTable variable.
  • CU18032322-0 Profile Picture
    30 on at
    I have debugged and found that this is the RetailSalesLine table.
    The RecVersion of the standard table and the extension table are not the same.
  • Martin Dráb Profile Picture
    237,882 Most Valuable Professional on at
    I think that your statement The RecVersion of the standard table and the extension table are not the same isn't correct. The condition if (currentExtensionTable.RecVersion != extensionTableToUpdate.RecVersion) is about two versions of RetailSalesLine buffer, not about the standard table and the extension table, right?
     
    If you've tried my suggestion regarding reread() (see the first reply), what was the result?
  • CU18032322-0 Profile Picture
    30 on at
    I tried your suggestion regarding reread(), but I still got the same exception called UpdateConflict.
  • Martin Dráb Profile Picture
    237,882 Most Valuable Professional on at
    The error means that you're trying to update a record that was concurrently updated somewhere else. The logical next step is finding where it was updated.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 565 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 450 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans