ax 2012 how to create purchline for same purchtable purchid through code

hi all

i am trying to insert the purchline for the same purchtable -purchid

while inserting it is giving an error that record already exist

code as follows:

localinventdimid.inventsiteid = inventsiteid;

inventdimid = inventdimid::findorcreate(localinventdimid).inventsiteid;

purchline::initformpurchtable(purchtable);

purchline.createline(true,false,false);

please help if any body know.

thanks,

srikanth

Debug and check whether the line number gets properly updated.

Generally initFrom* methods will not be static

hi kranthi,

i am increment the line number in the code with 10 ,

is this write way to do …

thanks,

srikanth

Hi Srikanth,

You did not mention AX version.

But have a look under Purchline table > indexes. In AX 2012, there are at least 3 unique indexes. Make sure your honours all these conditions.

For creating purchase line records, you may want to consider using ‘AxPurchLine’ class. Example here - http://shrishailtechnologies.wordpress.com/2012/04/27/ax-2012-x-code-to-create-and-post-purchase-order-invoice/

HI harish,

it is version of ax 2012 , i am able to create line while incrementing the line number by 10 , is this write way to do ,

please guide me if it is wrong

thanks,

srikanth

Hi Srikanth,

PurchLine purchline;

purchLine.initFromPurchTable(purchTable::find(“your purch id”));

axPurchLine = AxPurchLine::newPurchLine(purchLine);
axpurchLine.parmItemId(“itemid″);
axPurchLine.parmPurchQty(10);
axPurchLine.parmPurchPrice(100);
axPurchLine.doSave();

Try this.Hope it will solve your problem.