Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Server

Microsoft Dynamics AX 2009 : Processing Business Tasks - Creating purchase orders

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
1/1/2012 6:12:15 PM
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.

How to do it...

  1. 1. 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.initFromVendTable(VendTable::find('1001'));
    if (!purchTable.validateWrite())
    {
    throw Exception::Error;
    }
    purchTable.insert();
    purchLine.PurchId = purchTable.PurchId;
    purchLine.ItemId = '1205';
    purchLine.createLine(true, true, true, true, true, true);
    ttscommit;
    }


  2. 2. Run the class to create a new purchase order.

  3. 3. Open Accounts payable | Purchase Order Details to view the created purchase order:

How it works...

First we create a new class, which will run our code using its main(). Here we place all the code into a ttsbegin/ttscommit pair to make sure everything is rolled back if something goes wrong.

The method starts with generating the next number for a new purchase order.

Next, we call initValue() and initFromVendTable() to initialize various purchTable fields. Normally, the argument of initFromVendTable() should come from a user selection screen or other source. For demonstration purposes, here we simply use the first vendor number from the list.

If we pass validation of validateWrite() successfully, we create a purchase order header by calling purchTable.insert().

The next thing to do is to create purchase order lines. Here we need minimal information. First, we assign a purchase order number and then we set the item number. As previously the item number should come from user input or some other source. For demonstration purposes, we use item 1205 from the inventory list.

And finally, we call createLine() on the purchLine table to create a line. This method could be called a number of times depending on the number lines that need to be created. This method accepts a number of optional boolean arguments:

  • Perform data validations before saving? The default is false.

  • Initialize from PurchTable table? The default is false.

  • Initialize from InventTable table? The default is false.

  • Calculate inventory quantity? The default is false.

  • Add miscellaneous charges? The default is true.

  • Use trade agreements to calculate item price? The default is false.

Other -----------------
- Active Directory Domain Services 2008 : Delete a Computer Object
- Active Directory Domain Services 2008 : Create a Computer Object
- Windows Server 2008 Server Core : Managing the System Time with the W32Tm Utility
- Microsoft Dynamics CRM 4.0 Accelerators : Analytics Accelerator (part 2) - Analytics Accelerator Installation
- Microsoft Dynamics CRM 4.0 Accelerators : Analytics Accelerator (part 1)
- Microsoft Dynamic CRM 4.0 : Google Maps Integration
- Microsoft Systems Management Server 2003 : Disaster Recovery - Backing Up the Site Through Systems Management Server
- Microsoft Systems Management Server 2003 : Disaster Recovery - Backup Process Flow
- InfoPath with Sharepoint 2010 : Create a Master or Detail Display Form for SharePoint Lists
- Add an InfoPath Form Web Part to a SharePoint Web Part Page
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server