Sales order posting is also done in a very similar way to posting a purchase order. The posting function can be executed from code and can be integrated into various customizations.
In this recipe, we will use a standard Dynamics AX API to post and print a sales packing slip document from code. As an example, we will post and print a packing slip for the sales order created in the previous recipe.
How to do it...
-
1. In AOT, create a new class called SalesOrderPost with the following code (replace SO-100160 with your number):
class SalesOrderPost
{
}
public static void main(Args _args)
{
SalesFormLetter salesFormLetter;
salesTable salesTable;
;
salesTable = SalesTable::find('SO-100160');
salesFormLetter = SalesFormLetter::construct(
DocumentStatus::PackingSlip);
salesFormLetter.update(
salesTable,
systemdateget(),
SalesUpdate::All,
AccountOrder::None,
NoYes::No,
NoYes::Yes);
}
-
-
How it works...
First, we create a new class named SalesOrderPost with a main() method.
The method starts with finding sales order SO-100160, which we created in the previous recipe. Here, we would normally replace this code with user input or an output from another source.
Next, we call construct() on the SalesFormLetter class to create a new salesFormLetter instance. The method accepts an argument of type DocumentStatus, which defines the type of posting. Here, we use DocumentStatus::PackingSlip for sales packing slip posting. construct() also accepts a second optional boolean argument, which controls whether a new SalesParmUpdate record, used for sales order posting grouping, should be created. The default is true.
And finally, we call update() on salesFormLetter, which does actual posting. It accepts a number of arguments:
-
The sales order header record, i.e. SalesTable.
-
-
The quantity to be posted. The default is SalesUpdate::All.
-
This argument is not used. The default is AccountOrder::None.
-
-
-
-
-
There's more...
SalesFormLetter could also do other types of posting, like order confirmation, picking list, or invoice. For example, to invoice for the sales order, replace the code:
salesFormLetter = SalesFormLetter::construct(
DocumentStatus::PackingSlip);
with:
salesFormLetter = SalesFormLetter::construct(
DocumentStatus::Invoice);
Open Accounts receivable | Sales Order Details, select the previously specified sales order, click theInquiries button, and choose Invoice to view the results:
- 1. In AOT, create a new class called SalesOrderPost with the following code (replace SO-100160 with your number):
class SalesOrderPost { } public static void main(Args _args) { SalesFormLetter salesFormLetter; salesTable salesTable; ; salesTable = SalesTable::find('SO-100160'); salesFormLetter = SalesFormLetter::construct( DocumentStatus::PackingSlip); salesFormLetter.update( salesTable, systemdateget(), SalesUpdate::All, AccountOrder::None, NoYes::No, NoYes::Yes); }
The sales order header record, i.e. SalesTable.
The quantity to be posted. The default is SalesUpdate::All.
This argument is not used. The default is AccountOrder::None.
salesFormLetter = SalesFormLetter::construct(
DocumentStatus::PackingSlip);
salesFormLetter = SalesFormLetter::construct(
DocumentStatus::Invoice);
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.