Sunday 5 February 2012

Create Sales Quotation using X++ Code in Ax2012


static void CreateSalesQuotation(Args _args)
{
    AxSalesQuotationTable    AxSalesQttable;
    AxSalesQuotationLine     AxSalesQtline;
    SalesQuotationLine      SalesQuotationLine;
    salesQuotationTable     salesQuotationTable;
    CustTable     custTable;
    SalesQty  salesQty;
    ;
    salesQty = 2;
    AxSalesQttable =  new AxSalesQuotationTable();
    AxSalesQttable.parmCustAccount('C-20');
    AxSalesQttable.parmCurrencyCode('USD');        
    AxSalesQttable.save();
    AxSalesQtline =  new AxSalesQuotationLine();//::construct(smmQuotationLine);

    AxSalesQtline.axSalesQuotationTable(AxSalesQttable);

    AxSalesQtline.parmQuotationId(AxSalesQttable.parmQuotationId());
    AxSalesQtline.axSalesQuotationTable(AxSalesQttable);
    AxSalesQtline.parmItemId('1000');

    AxSalesQtline.parmSalesQty(salesQty);

    AxSalesQtline.parmInventDimId('00001005_069');
    //AxSalesQtline.par

    AxSalesQtline.parmcurrencyCode('USD');
    AxSalesQtline.save();
}

6 comments:

  1. Thank you, this code works and helps a lot. :)

    ReplyDelete
  2. Hi Muhammad,
    Do you have a code, how to create the Request For Quotation through X++ code.


    Thanks in advance.

    ReplyDelete
  3. Hi Muhammed,
    how would you do it if you were to update an existing quote?

    ReplyDelete
  4. Thank you for sharing your code, below is a example which reads from a file as well could be useful
    static void SSS_FileReadCreateQuote(Args _args)
    {
    CommaIO ioIn;
    FileNameOpen filenameIn;
    Dialog d;
    DialogField dfFileIn;
    DialogField dfSkip;
    DialogField dfInsBrand;
    DialogField dfUpdItem;

    container inLine;
    ItemId itemId;
    InventTable inventTable;
    SalesQuotationTable salesQuotationTable;
    SalesQuotationLine salesQuotationLine;
    InventDim inventDim;

    AxSalesQuotationTable axSalesQuotationTable;
    AxSalesQuotationLine axSalesQuotationLine;
    CustTable custTable = custTable::find("016463");
    ;
    d = new dialog('Create quote from file');
    dfFileIn = d.addField(extendedtypestr(FilenameOpen), 'Read from');
    dfSkip = d.addField(enumStr(NoYes), 'Skip first line');

    window 20,5 at 0, 0;

    if (d.run() && dfFileIn.value())
    {
    ioIn = new CommaIo(dfFileIn.value(), 'R');
    if (! ioIn)
    throw error(strfmt("@SYS18678", dfFileIn.value()));

    ioIn.inFieldDelimiter(",");
    if(dfSkip.Value() == NoYes::Yes) //Skip first line
    inLine = ioIn.read();
    inLine = ioIn.read();

    inventDim.InventSiteId = 'SSS';
    inventDim.InventLocationId = '10';
    inventDim = InventDim::findOrCreate(inventDim);

    axSalesQuotationTable = new AxSalesQuotationTable();
    axSalesQuotationTable.parmCustAccount(custTable.AccountNum);
    axSalesQuotationTable.parmCurrencyCode(custTable.Currency);
    axSalesQuotationTable.save();
    info(strFmt("%1", axSalesQuotationTable.parmQuotationId()));

    while (inLine)
    {
    itemId = conPeek(inLine, 1);
    inventTable = inventTable::find(itemId);
    info(strFmt("%1", inventTable.ItemId));

    if (inventTable)
    {
    axSalesQuotationLine = new AxSalesQuotationLine();

    axSalesQuotationLine.parmQuotationId(axSalesQuotationTable.parmQuotationId());
    axSalesQuotationLine.axSalesQuotationTable(axSalesQuotationTable);
    axSalesQuotationLine.parmItemId(inventTable.ItemId);

    axSalesQuotationLine.parmSalesQty(1);
    axSalesQuotationLine.parmCostPrice();

    axSalesQuotationLine.parmInventDimId(inventDim.inventDimId);

    axSalesQuotationLine.parmcurrencyCode(custTable.Currency);
    axSalesQuotationLine.save();
    }
    inLine = ioIn.read();
    }//end fil*/

    //costprice is not set so we set it afterwards.
    ttsBegin;
    while select forUpdate SalesQuotationLine
    where SalesQuotationLine.QuotationId == axSalesQuotationTable.parmQuotationId()
    {
    salesQuotationLine.CostPrice = SalesQuotationLine.mcrCalcCostPrice();
    salesQuotationLine.update();
    }
    ttsCommit;

    info('over and out');
    }
    }

    ReplyDelete
  5. Hi, this works like a charm for 1 item. What do i have to do to make this work for multiple items?

    ReplyDelete