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, ...
Unanswered

X++ Post Product Receipt with PO Changed Management activated

(0) ShareShare
ReportReport
Posted on by 1,243

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

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

#1
Martin Dráb Profile Picture

Martin Dráb 523 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 408 Super User 2026 Season 2

#3
CU10121822-0 Profile Picture

CU10121822-0 354

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans