X++ code to create purchase order with dialog box parameters (vendor account number , site id, warehouse id , item number ) in D365 F & O

 class BASPurchOrderCreation extends RunBase

{

    DialogField VenAccount, itemNumber, inventSiteid, inventLocationid;


    VendAccount vendAccount;


    ItemId itemId;


    InventSiteId SiteId;


    InventLocationId LocationId;


       


    Object Dialog()

    {

        Dialog dialog;

        dialog = super();

        // Set a title fordialog

        dialog.caption( 'Purchase Order Creation');

        // Add a new field to Dialog

        VenAccount = dialog.addField(extendedTypeStr(VendAccount), 'Vendor Account' );


        itemNumber = dialog.addField(extendedTypeStr(ItemId), 'Item Number' );


        inventSiteid = dialog.addField(extendedTypeStr(InventSiteId), 'Site ID' );


        inventLocationid = dialog.addField(extendedTypeStr(InventLocationId), 'Warehouse ID' );


        return dialog;

    }


    public boolean getFromDialog()

    {

           

        // Retrieve values from Dialog

        vendAccount =VenAccount.value();


        itemId=itemNumber.value();


        SiteId=inventSiteid.value();


        LocationId=inventLocationid.value();


        return super();

    }


    public void run()

    {

        // Data Entities Declaration

        PurchPurchaseOrderHeaderV2Entity purchTable;

        PurchPurchaseOrderLineV2Entity purchLine;


        //Purchase Order Header Creation


        purchTable.initValue();

        purchTable.OrderVendorAccountNumber = vendAccount;

        purchTable.insert();


        //Getting saleId to create lines

        PurchId purchId = purchTable.PurchaseOrderNumber;


        // Purchase Order Line Creation


        purchLine.initValue();

        purchLine.PurchaseOrderNumber = purchId;

        purchLine.ItemNumber = itemId;

        purchLine.ReceivingSiteId = SiteId;

        purchLine.ReceivingWarehouseId = LocationId;

        purchLine.insert();


        Info(strFmt("Purchase order %1 has been created",purchTable.PurchaseOrderNumber));


        //Updating sales order by SalesFromLetter class


        PurchFormLetter purchFormLetter;

        

        PurchTable purchUpate = PurchTable::find(purchId);


        //Posting PO Confirmation,I guess its mandatory

        //You cannot do invoice without doing PO confirm

        purchFormLetter = PurchFormLetter::construct(DocumentStatus::PurchaseOrder);

        purchFormLetter.update(purchUpate,strFmt("PO_%1", purchTable.PurchaseOrderNumber));


        //Posting Packing slip

        purchFormLetter = PurchFormLetter::construct(DocumentStatus::PackingSlip);

        purchFormLetter.update(purchUpate,strFmt("PO_%1", purchTable.PurchaseOrderNumber));

        info('Packing slip posted');


        ////Posting PO Invoice

        purchFormLetter = PurchFormLetter::construct(DocumentStatus::Invoice);

        purchFormLetter.update(purchUpate,strFmt("Inv_%1", purchTable.PurchaseOrderNumber));

        info('Invoice posted');


            

    }


    public static void main(Args _args)

    {

        BASPurchOrderCreation purchorder = new BASPurchOrderCreation();

        if(purchorder.prompt())

        {

            purchorder.run();

        }



    }


}

Comments

Popular posts from this blog

how to post trade agreement journals automatically using x++ code

How to Create a wizard in x++ d365

x++ code to submit and approve and reject the invent movement workflow in d365 F&O