How to create Purchase order Product receipt through X++ in Ax2012 ?

Hi friends,

  1. I want to create multiple Product receipt from single Purchase order Line.

  2. I have totally 10 Purchase Qty. Now i am receiving 5 Purchase qty only.

PurchFormLetter_PackingSlip purchProductReceipt;

// let’s say, product receipt is for PO: ‘PO-0030’

purchTbl = PurchTable::find(SRVTable.PurchId);

// initiate PurchFormLetter_PackingSlip class

purchProductReceipt = PurchFormLetter::construct(DocumentStatus::PackingSlip);

purchProductReceipt.showQueryForm(false);

ttsBegin;

select forUpdate purchLine

where purchLine.PurchId == purchTbl.PurchId

&& purchLine.IsDeleted == NoYes::No;

if(purchLine)

{

purchLine.PurchReceivedNow = 5;

purchLine.InventReceivedNow = 5;

purchLine.update();

}

ttsCommit;

}

// invoke product receipt

// input parameters are POtable, Receipt num, date of receiving, qty, account order

purchProductReceipt.update(purchTbl, today(), today(), PurchUpdate::ReceiveNow, AccountOrder::None, false, false);

This Code is Working fine for multiple Product Receipt.

3.When I activate the Purchase order Workflow . The Above Code is Not working .
it throw error at the time of updating the Purchase order Line.
Error(“Changes to the document are only allowed in state Draft, because change management is activated.”)

  1. So, Not possible to update Purchline Table. Because of change management(Workflow) is activated . PurchLine table is updated only when PO document status is draft.

  2. Please Suggest the Solution

This means the purchLine is not allowed to update, this is intentional and you can find the restriction in \Classes\VersioningDocument\change

In this case, you should bypass the update. Call doUpdate() after filling the required fields in purchLine. (you can find the similar code in \Classes\PurchPackingSlipJournalPost\updateSourceLine)

Thanks Mr. Kranthi , i am using doUpdate() . Its working fine now

Hi,

Can we use the same method for invoicing of purchase order based on the product receipt which we have created?

Like, I want to invoice a purchase order but based on the product receipt which i have created for that only.

is it possible with the update method?

Please give me some suggestions.

Thanks in advance,

Vijay Solanki.