Creating purchase orders from code is one of the many things that are required when building custom functionality. Normally, the user selects only a few bits of information like vendor account, item number, delivery date, etc. and the rest is created by the system. It is also possible that purchase orders may be created as part of some process in custom modules.
In this recipe, we will learn how to create a purchase order from X++ code. We will use a standard method provided by the application.
In AOT, create a new class called PurchaseOrderCreate with the following code:
class PurchaseOrderCreate { } public static void main(Args _args) { NumberSeq numberSeq; PurchTable purchTable; PurchLine purchLine; ; ttsbegin; numberSeq = NumberSeq::newGetNumFromCode( PurchParameters::numRefPurchId().numberSequence, true); purchTable.PurchId = numberSeq.num(); purchTable.initValue(); purchTable...