While PO positng getting error as "cannot edit a record in Purchase orders (PurchTable).Operation canceled "

Through job am trying to invoice one PO.Once po is posted then i can go for invoice if am not wrong.

So for PO posting my code is…

PurchTable purchTable;
PurchFormLetter purchFormLetter;
;

Select purchTable where purchTable.PurchId == ‘00010241_072’;
purchFormLetter = PurchFormLetter::construct(DocumentStatus::PurchaseOrder);
purchFormLetter.update(purchTable, purchTable.PurchId);

But failed to do posting as am getting the error "cannot edit a record in Purchase orders (PurchTable).Operation canceled "

By debugging and came across that PurchFormLetter ->update()->then createParmUpdate()

In this method am getting parmid as “00180524_001” then at end cursor comes to insert()

purchParmUpdate.ParmId = this.parmId();

if (! PurchParmUpdate::exist(purchParmUpdate.ParmId))
purchParmUpdate.insert();

when i went inside it goes PurchLineType.insert()

purchTable = purchLine.purchTable(update); Again going inside i found that purchid is taking parmid 00180524_001 it should take purchid,so as it is not there in purchTable so record is null.

PurchTable purchTable(boolean update = false)
{
return PurchTable::find(this.PurchId, update);
}

Why this.purchid is taking parmid instead of purchid ?

Not even job am unable to do post in front end also.

When i am selecting po and posting->PO->then i get this error instead of opening posting form.

what could be the reason ?

How is it that your invoice posting tries to create new order lines (purchLineType.insert())? It makes no sense to me.

Also PurchParmUpdate.insert() is not implemented in standard AX2009 (at least in SP1 RU7), so if you can step into it, you must have some custom code there.