Dynamics Ax Creating sales orders with the SalesAutoCreate class

Many projects use an interface to import their sales orders, because of this a SalesAutoCreate class was created. This class is easily extendable and customizable.The first thing to do is designing a buffer table, like this one for example:

Sales order import table
Sales order import table

After this we can start extending a new class from the SalesAutoCreate class and modifying the construct on the SalesAutoCreateClass .

After the construct your buffer record should be passed in the new or a parm method could also be an option.

When extending from the SalesAutoCreate class some methods must be implemented:

  • setCust
  • salesType
  • recordExist
  • nextRecord
  • invoiceAccount

In my example I’ve implemented them like this:

The next step is setting our table and line fields by overriding the setSalesTable and setSalesLine methods and make sure that you always call the super first. Notice that you need to call the createSalesTable and createSalesLine to do the insert.

you should have a class looking like this.

Sales auto create class
Sales auto create class

the final step is to call the logic from a job or a RunBaseBatch class, make sure that you select records on the same tier as the nextRecord will run or else it will fail. Preferably on the server tier. 🙂

This example lacks some validation whether the record has already been processed or not, so it will created the same records every time it is called. You could implement your own method on the SalesAutoCreate class, call it from the create method and override it on your custom class, like this.

3 thoughts on “Dynamics Ax Creating sales orders with the SalesAutoCreate class”

  1. Does this SalesAutoCreate class get used by the AIF?

    We use the AIF to create sales orders and are trying to specify a custom date to be utilized when looking up pricing. We are trying our best to understand where in the process the price lookup occurs when SalesLines interact with the “PriceDisc” trade agreement records.

    1. Hi,

      I don’t think AIF uses the SalesAutoCreate class, the easiest way to find this is out is debugging AIF 😉
      I’m not sure but isn’t there a setPriceDisc method on the AxSalesLine class, maybe have a look at the setSalesQty method too.

      Kind regards,

      Kevin

Leave a Reply