Error when creating multiple purchase orders through x++ code.

Hi All,

When I try to create multiple purchase orders from newly created form, it is throwing error “Order Account cannot be changed” but if I create single purchase order, I can be able to create it. What can be done to resolve this?

Regards,

Kuppusamy S

Hi,

Are there any customization around this area? Also can you post your code?

Hi Harish,

This is the code I ve done for creating purch order from my form.

while select table where table .fieldid == _table .fieldid
{
numberSeq = NumberSeq::newGetNumFromCode(PurchParameters::numRefPurchId().NumberSequence,true);
purchtable.initValue();
purchtable.PurchId = numberSeq.num();
purchtable.PurchaseType = PurchaseType::Purch;
purchtable.OrderAccount = table .Vendor;
purchtable.initFromVendTable(VendTable::find(purchtable.OrderAccount));
if (!Purchtable.validateWrite())
{
throw Exception::Error;
}
else
{
purchtable.insert();
}
purchLine.clear();
purchLine.PurchId = purchtable.PurchId;
purchLine.ItemId = table.ItemID;
select invent
where invent.InventSiteId == table.inventsiteid;
purchLine.InventDimId = InventDim::findOrCreate(invent).inventDimId;
PurchLine.createLine(true, true, true, true, true, true);
}

Regards,

Kuppusamy S

Hi,

Actually I am facing the same problem. How did you resolve it ?

Thank you in advance.

Hi,

As per the error message, i think that when you are creating multiple PO, the first record is getting created without any problem but when the second PO is getting created, it is changing the vendor account of the first record only. order account is nothing but vendor code in purch table.

Check that, may be that is creating problem.

Pranav…

Hi, Try clearing PurchTable everytime. PurchTable.clear() initially and start doing all other process. This may work. Go for a try. Regards, Kuppusamy S

Hello,

I had already purchtable.clear() but it didn’t resolve the problem, so I put Purchtable = null; before the clear and it works perfectly now !

It seems that purchTable_Orig.RecId was not empty in the validateWrite method…

Thank you very much !

Hello,

I’ve just got the same error when I try the creating Sales Order through xpp code, I put Salestable = null; SalesTable.clear() and the code running as well.

Thanks M.A.B very much.