Skip to main content
Post a question

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

After doing a product receipt using x++ code project transactions are not getting created

Like (2) ShareShare
ReportReport
Posted on 13 Mar 2025 09:33:33 by 442
hi All,
I am facing an issue when i do the product receipt with below code. 
 
Issue - Project transactions are not getting created on the project which is assigned on the purchase order, but if i do the product receipt from UI then its creating for same PO.
 
Expected -
 
private TESTPOReceiptResponseContract createProductReceipt(ENGIEPOReceiptRequestContract   _requestContract)
    {
        PurchFormLetter                 purchFormLetter;
        PurchParmTable                  purchParmTable;
        PurchParmLine                   purchParmLine;
        PurchFormletterParmData         purchFormLetterParmData;
        ENGIEOrderLineRequestContract   orderLineContract   = _requestContract.parmOrderLineContract();
        PurchTable                      purchTable          = PurchTable::find(orderLineContract.parmPurchaseOrderId());
        PurchLine                       purchLine           = PurchLine::find(purchTable.PurchId, orderLineContract.parmLineNumber());

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

        PurchParmUpdate purchParmUpdate = purchFormLetterParmData.parmParmUpdate();

        purchParmTable.clear();
        purchParmTable.TransDate                = _requestContract.parmProducReceiptDate();
        purchParmTable.Ordering                 = DocumentStatus::PackingSlip;
        purchParmTable.ParmJobStatus            = ParmJobStatus::Waiting;
        purchParmTable.Num                      = _requestContract.parmCoupaId();
        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;
        PurchParmLine_Asset                       purchParmLine_Asset;
        purchParmTable.insert();
        
        purchParmLine.initFromPurchLine(purchLine);
        purchParmLine.ReceiveNow    = strScan(_requestContract.parmTransactionType(), "@SYS53072" , 1, strLen(_requestContract.parmTransactionType()))
                                        ? _requestContract.parmTotal()
                                        : _requestContract.parmQuantity();
        purchParmLine.ParmId        = purchParmTable.ParmId;
        purchParmLine.TableRefId    = purchParmTable.TableRefId;
        purchParmLine.setQty(DocumentStatus::PackingSlip, false, true);
        purchParmLine.setLineAmount();
        purchParmLine.insert();

        if(purchLine.AssetId != '')
        {
            purchParmLine_Asset.initFromPurchParmLine(purchParmLine);
            purchParmLine_Asset.initFromPurchLine(purchLine);            
            purchParmLine_Asset.insert();
        }

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

       
        return this.getResponseContract("@ENG_Labels:ProductCeceiptCreated", true);
    }
 
While debug i found system is calling method runProjectPostings() of class PurchFormLetter_PackingSlip and posting projectpackingslip, same code is not getting hit when i do the PR using above code. Please let me know if there is any way i can call same method using purchFormLetter.run();
 
I did in below way and that is working as well-
after successful run purchFormLetter.run(), i called below code explicitly, but i think this should get execute in standard logic. Please let me know if we can achieve this in better way.
 
public void runRemainProjectUpdates(PurchFormLetter _purchFormLetter, ParmId _parmId)
    {
        FormletterOutputContract outputContract  = _purchFormLetter.getOutputContract();
        VendPackingSlipVersion  localVendPackingSlipVersion;
        VendPackingSlipJour     localVendPackingSlipJour;
        VendPackingSlipTrans    localVendPackingSlipTrans;
        PurchLine               localPurchLine;
        SalesLine               localSalesLine;
        SalesFormLetter         salesFormLetter;

        if (ProjParameters::find().AutomaticItemConsumption == NoYes::Yes )
        {
            select firstonly RecId, AccountingDate from localVendPackingSlipVersion
                where localVendPackingSlipVersion.ParmId == _parmId
                exists join localVendPackingSlipJour
                    where localVendPackingSlipVersion.VendPackingSlipJour == localVendPackingSlipJour.RecId
                    exists join localVendPackingSlipTrans
                        where localVendPackingSlipTrans.VendPackingSlipJour == localVendPackingSlipJour.RecId
                        exists join localPurchLine
                            where localPurchLine.InventTransId == localVendPackingSlipTrans.InventTransId &&
                                 !localPurchLine.IsDeleted &&
                                  localPurchLine.ItemRefType == InventRefType::Sales &&
                                  localPurchLine.InventRefId &&
                                  localPurchLine.InventRefTransId
                            exists join localSalesLine
                                where localSalesLine.InventTransId == localPurchLine.InventRefTransId &&
                                  localSalesLine.ProjId &&
                                  localSalesLine.SalesType == SalesType::ItemReq &&
                                  (localSalesLine.SalesStatus == SalesStatus::None
                                    || localSalesLine.SalesStatus == SalesStatus::Backorder
                                    || (localSalesLine.SalesStatus == SalesStatus::Delivered
                                            && (localSalesLine.RemainInventPhysical != 0)));

            if (localVendPackingSlipVersion.RecId)
            {
            
                salesFormLetter = SalesFormLetter::newFromPurchFormLetter_PackingSlip(SysOperationHelper::base64Encode(outputContract.parmJournalLinesPacked()),
                        DocumentStatus::ProjectPackingSlip);
                if (localVendPackingSlipVersion.AccountingDate)
                {
                    salesFormLetter.transDate(localVendPackingSlipVersion.AccountingDate);
                }

                salesFormLetter.prePromptInit();
                salesFormLetter.runOperation();
            
            }

        }
    }
 
 
 
 
 
 
Categories:

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,845 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,717 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans
Loading complete