Sunday 2 October 2011

Post/update sales quotation through X++

Unfortunately AX doesn't provide convenient API for sales quotation just like it provides for sales order which does the update in a few simple lines.


Eg.
salesFormLetter = SalesFormLetter::construct(DocumentStatus::PackingSlip); 
salesFormLetter.update(......)


For Sales quotation, it has the API for part of the status, that's to post/update "Lost" or "Cancel".
To post/update "Quotation" (Sent) or "Confirmation", you'll have to do a little bit of work.


Looking into \Classes\SalesQuotationEditLinesForm\mainOnServer(), it has almost everything you need to update the quotation, but it needs a bit of modification to run without user interaction.  The .prompt() in ::mainOnServer() collect some input through user interaction, you'll need to pass in these parameters to update the quotation so that you can skip the .prompt().


I'll skip elaborate further as I think by looking at a sample code, you'll immediately gets the idea.

The following code assume you have passed in the variable 'salesQuotationTable'.


=================================================================
/* UPDATE SALES QUOTATION TO "Sent" or "Confirmation"


SalesQuotationEditLinesForm  salesQuotationEditLinesForm;
ParmId                       parmId;
;


salesQuotationEditLinesForm = SalesQuotationEditLinesForm::construct(DocumentStatus::Quotation); //DocumentStatus
parmId                      = salesQuotationEditLinesForm.parmId();


salesQuotationEditLinesForm.initParmSalesQuotationTable(salesQuotationTable);


salesQuotationEditLinesForm.parmId(parmId);
salesQuotationEditLinesForm.parmTransDate(systemDateGet());
salesQuotationEditLinesForm.prePromptInit();
salesQuotationEditLinesForm.initParameters(NoYes::No, //printFormletter,
                                           NoYes::No, //transferHours2Forecast,
                                           NoYes::No, //transferExpenses2Forecast,
                                           NoYes::No, //transferFees2Forecast,
                                           NoYes::No, //transferItems2Forecast,
                                           'TheReasonCode', //reasonCode,
                                           NoYes::No); //usePrintManagement)
salesQuotationEditLinesForm.run();


=================================================================


/* UPDATE SALES QUOTATION TO "Lost" or "Cancelled"
salesQuotationUpdate = SalesQuotationUpdate::constructFromSalesQuotationTable(salesQuotationTable, SalesQuotationStatus::Cancelled);
SalesQuotationUpdate.run();

=================================================================



No comments:

Post a Comment