Thursday 16 July 2015

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: https://msdn.microsoft.com/en-us/library/aa659696.aspx.
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;
   super();
   if (element.args().dataset() == tableNum(CustTable) && element.args().record().(fieldNum(CustTable, AccountNum)))
   {   
      custTable = element.args().record();
      this.query().dataSourceTable(tablenum(CustInvoiceJour)).clearDynalinks();    
      this.query().dataSourceTable(tableNum(CustInvoiceJour)).addRange(fieldNum(CustInvoiceJour, RecId)).value(strFmt('((OrderAccount == "%1") || (InvoiceAccount == "%1"))', custTable.AccountNum));
   }
(…)

I hope this is helpful!

Happy DAXing
..........

No comments:

Post a Comment