How to set sales packing slip or sales invoice number manually through X++ in AX2012?

Problem.

In Microsoft Dynamics AX, sales packing slip’s number is generated from number sequence. In my customization, I was posting inventory documents and sales packing slips for „Picked” quantities automatically and I wanted to be able to set sales packing slip’s number from X++ code, based on some business logic. This description is for posting sales packing slip, but it can also be used for sales invoices.

Tool.

In Microsoft Dynamics AX2012, there is a tool, which allows user to edit sales packing slip number, but is country specific and it is available for one of these country region codes: LT, LV, EE, PL, HU and CZ. If you are in this group, you should be able to see „Edit invoice ID on sales order” parameter on AR module parameters form. If you check this parameter, you will see „Packing slip” field, where you can type what you want.

Sales packing slip - NumW
Sales packing slip – NumW

But what if we want to set our sales packing slip number from X++ code? I made a customization to pass our value to „Num_W” field, so we will use field and classes, which already exist.

Step by step.

To be able to set sales packing slip number manually, we will need three steps:

1. Pass our value to SalesFormLetter class, which is responsible for posting documents,
2. Pass our value to SalesFormLetterContract class, which is working on client and server,
3. Pass our value to SalesFormLetterParmData class, which is creating SalesParmTable.

So…

1. Declare „numW” variable in \Classes\FormLetterJournalCreate.

2. Declare „numW” variable in \Classes\SalesFormLetter and create parmNumW() method.

3. Declare „numW” variable in \Classes\SalesFormLetterContract, put it in „ParmListSales” macro (it has to be passed to server-side) and create parmNumW() method.

4. Declare „numW” variable in in \Classes\SalesFormLetterParmData, create parmNumW() method and pass „numW” value to SalesParmTable in createParmTable() method.

That is all. Now, you can use our parmNumW() method when posting sales packing slip like this:

Leave a Reply