Customizing the system-generated query of the Invoice journal form

When creating a Sales order in Dynamics AX 2012, you can define both a “Customer account” and an “Invoice account”. The Customer account identifies the customer for which the Sales order is being created, and the Invoice account references the account number of the customer to invoice, in case it is different.

If you open the Invoice journal form from the Customer list page, you see only the transactions that were created for the customer selected in the grid, and not the transactions that were invoiced to this customer:

1- Go to Accounts receivable > common > Customers > All customers

2- In the ribbon, click the Invoice tab

3- Click the Invoice journal button in the Journals button group

If you want to modify this behavior, you will need to modify the query that is executed when the CustInvoiceJournalform is opened.

This is a good example of customization that would require accessing and modifying the system-generated query of a form, like explained here:

Setting the AutoQuery property on a form data source to Yes – as in the case here – causes the system to automatically generate the query that retrieves data to display in the form.

In this scenario, modifying the system-generated query to display a different set of data can be done in the init method of the data source of the form (in bold below):

Form: CustInvoiceJournal

Data source: CustInvoiceJour

Method: init

public void init()


   QueryBuildDataSource   queryDataSourceLink;
   CustInvoiceJour              custInvoiceJourLoc;
   SalesTable                      salesTableLoc; 
   TAMDeduction           tamDeduction;

   CustTable              custTable;


   if (element.args().dataset() == tableNum(CustTable) && element.args().record().(fieldNum(CustTable, AccountNum)))
      custTable = element.args().record();
      this.query().dataSourceTable(tableNum(CustInvoiceJour)).addRange(fieldNum(CustInvoiceJour, RecId)).value(strFmt(‘((OrderAccount == “%1”) || (InvoiceAccount == “%1”))’, custTable.AccountNum));



I hope this is helpful!




“Microsoft provides programming examples for illustration only, without warranty expressed or implied, including, but not limited to, the implied warranties of merchantability or fitness for a particular purpose. This mail message assumes that you are familiar with the programming language that is being demonstrated and the tools that are used to create and debug procedures.” This is not an officially tested solution by Microsoft and should be fully tested before implementation.