Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Unanswered

X++ Post Product Receipt with PO Changed Management activated

Posted on by 1,217

Hi All,

I had written a method to post product receipt after received external data. The code was running fine for certain product receipt. However on and off, the error below is encountered. Because the change management is activated, hence the error below occured.

Changes to the document are only allowed in state Draft, because change management is activated.

But the issue is not happen on every product receipt, seem only product receipt that have multiple batch number got this error.

Below is the code that use to post product receipt.

public static boolean postProductReceipt(ProductReceiptHeaderInterfaceEntity _prcHeaderInterfaceEntity)
    {
        boolean poReceiptPosted;

        PurchFormLetter             purchFormLetter;
        PurchFormletterParmData     purchFormLetterParmData;
        PurchParmUpdate             purchParmUpdate;
        PurchParmTable              purchParmTable;
        PurchParmLine               purchParmLine;
        PurchTable                  purchTable;
        PurchLine                   purchLine;
        PurchId                     purchId;
        Num                         packingSlipId;
        VendPackingSlipJour         vendPackingSlipJour;
        InventTrans                 inventTrans;
        InventTransOrigin           inventTransOrigin;

        ProductReceiptLineInterfaceEntity prcLineInterfaceEntity;

        purchId         = _prcHeaderInterfaceEntity.PurchaseOrderNumber;
        packingSlipId   = _prcHeaderInterfaceEntity.ProductReceiptNumber;
        purchTable      = PurchTable::find(purchId);

        ttsBegin;
        
        purchFormLetterParmData = PurchFormletterParmData::newData(
        DocumentStatus::PackingSlip,
        VersioningUpdateType::Initial);
    
        purchFormLetterParmData.parmOnlyCreateParmUpdate(true);
        purchFormLetterParmData.createData(false);
        purchParmUpdate = purchFormLetterParmData.parmParmUpdate();

        purchParmTable.clear();
        purchParmTable.initValue();

        purchParmTable.TransDate                = _prcHeaderInterfaceEntity.ProductReceiptDate;//SystemDateGet();
        purchParmTable.Ordering                 = DocumentStatus::PackingSlip;
        purchParmTable.ParmJobStatus            = ParmJobStatus::Waiting;
        purchParmTable.Num                      = packingSlipId;
        purchParmTable.PurchId                  = purchTable.PurchId;
        purchParmTable.PurchName                = purchTable.PurchName;
        purchParmTable.DeliveryName             = purchTable.DeliveryName;
        purchParmTable.DeliveryPostalAddress    = purchTable.DeliveryPostalAddress;
        purchParmTable.OrderAccount             = purchTable.OrderAccount;
        purchParmTable.CurrencyCode             = purchTable.CurrencyCode;
        purchParmTable.InvoiceAccount           = purchTable.InvoiceAccount;
        purchParmTable.ParmId                   = purchParmUpdate.ParmId;
        purchParmTable.insert();

        while select purchLine join inventTrans Join inventTransOrigin
        where purchLine.PurchId == purchTable.purchId
             && inventTransOrigin.InventTransId == purchLine.InventTransId
             && inventTrans.InventTransOrigin == inventTransOrigin.RecId
             && inventTrans.StatusReceipt   == StatusReceipt::Registered
         
        {

            purchParmLine.InitFromPurchLine(purchLine); 
            
            purchParmLine.ReceiveNow    =  purchline.registeredInPurchUnit();
            purchParmLine.setInventReceiveNow();
            purchParmLine.ParmId        = purchParmTable.ParmId;
            purchParmLine.TableRefId    = purchParmTable.TableRefId;
            purchParmLine.setQty(DocumentStatus::PackingSlip, false, true);
            purchParmLine.setLineAmount();            
            purchParmLine.insert();
        }

        purchFormLetter = PurchFormLetter::construct(DocumentStatus::PackingSlip);
        purchFormLetter.transDate(systemDateGet());
        purchFormLetter.proforma(false);
        purchFormLetter.specQty(PurchUpdate::ReceiveNow);
        purchFormLetter.purchTable(purchTable);
    
        purchFormLetter.parmParmTableNum(purchParmTable.ParmId);
        purchFormLetter.parmId(purchParmTable.ParmId);
        purchFormLetter.purchParmUpdate(purchFormLetterParmData.parmParmUpdate());
        purchFormLetter.run();
        ttsCommit;

        select firstonly vendPackingSlipJour where vendPackingSlipJour.PurchId == _prcHeaderInterfaceEntity.PurchaseOrderNumber
            && vendPackingSlipJour.PackingSlipId == _prcHeaderInterfaceEntity.ProductReceiptNumber
            && vendPackingSlipJour.DeliveryDate == _prcHeaderInterfaceEntity.ProductReceiptDate;

        if(vendPackingSlipJour)
            poReceiptPosted = true;
        else
            poReceiptPosted = checkFailed('Posting not successful.');

        return poReceiptPosted;
    }

How can I overcome this issue?

Any advice is much appreciated.

Thanks.

Regards,
Teh

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,232 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,064 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans