Friday, September 26, 2014

Create Purchase Order And Post Invoice via X++

Following is X++ code to create purchase order and post the invoice using PurchFormLetter class.

static void CreatePOAndInvoice(Args _args)
{
    PurchTable      purchTable;
    PurchLine       purchLine;
    VendTable       vendTable = VendTable::find("1005");
    AxPurchTable    axPurchTable;
    AxPurchLine     axPurchLine;
    PurchFormLetter purchFormLetter;


    //update site and warehouse locations.
    vendTable.InventSiteId ='DC';
    vendTable.InventLocation = 'TW';
 
 
    //Create Purchase order
    purchTable.initFromVendTable(vendTable);

    axPurchTable = axPurchTable::newPurchTable(purchTable);
    axPurchTable.parmPurchaseType(PurchaseType::Purch);
    axPurchTable.parmDocumentStatus(DocumentStatus::PurchaseOrder);
    axPurchTable.parmAccountingDate(systemDateGet());
    axPurchTable.parmDeliveryDate(01\06\2012);
    axPurchTable.parmPurchStatus(PurchStatus::Backorder);
    axPurchTable.doSave();

    //Create PurchLine for item 1000
    purchLine.initFromPurchTable(purchTable);

    axPurchLine = AxPurchLine::newPurchLine(purchLine);

    axpurchLine.parmItemId("0002");
    axPurchLine.parmPurchQty(10);
    axPurchLine.parmPurchPrice(100);
    axPurchLine.doSave();

    //Posting PO Confirmation,I guess its mandatory
    //You cannot do invoice without doing PO confirm
    purchTable = axPurchTable.purchTable();
    purchFormLetter = PurchFormLetter::construct(DocumentStatus::PurchaseOrder);
    purchFormLetter.update(purchTable, strFmt("Inv_%1", purchTable.PurchId));

    //Posting PO Invoice
    purchFormLetter = PurchFormLetter::construct(DocumentStatus::Invoice);
    purchFormLetter.update(purchTable, strFmt("Inv_%1", purchTable.PurchId));

    info('Done.');
}

Monday, September 15, 2014

Create Sale Order using AIF service AX2012


SalesSalesOrderService will be required to place sales order. it is predefined service in AX2012. you will just need to perform following steps.

1-  Register Service (right click on service -->Add-In -->Register Service) and .

2-  System Administration --> Inbound ports -->{Add new salesorder service}

On c# create salesorder like this.

3-  Create c# web service project and add service reference 'SalesOrderServiceRef'

4-  public static void CreateSalesOrder()
        {
            var line = new AxdEntity_SalesLine()
            {
                ItemId = "0019",
                SalesQty = 42,
                SalesUnit = "ea"
            };
           
            var order = new AxdEntity_SalesTable()
            {
                CustAccount = "100001",
                PurchOrderFormNum = "xyz",
                ReceiptDateRequested = DateTime.Now.Date,
                SalesLine = new AxdEntity_SalesLine[] { line }
            };

            var orderList = new AxdEntity_SalesTable[] { order };
            var callContext = new CallContext() { Company = "USRT" };
            var client = new SalesOrderServiceClient();

            AxdSalesOrder o = new AxdSalesOrder();
            o.SalesTable = orderList;
            try
            {
                client.create(callContext, o);
                client.Close();
            }
            catch
            {
                client.Abort();
                throw;
            }
        }