Recently, in my Credit/Debit memo project, I needed to create a process that would show a list of available sales orders for a invoice account that could be “Credited or Debited”, then a list of vouchers for that sales order, then a list of items from that voucher, etc.. See the form below, and in the grid is where the filtered drop down boxes would be..
The sales order drop down was filtered by the invoice account and looked like the following..
This is not an out of the box lookup box, so the rest of this blog is going to explain how to create your own custom lookup query to display.
Since this was a custom process, it has custom tables, so on the ptnCreditDebitMemoLine table I created a static method that would perform the Dynamics Ax query. The method is below..
1: public client static void lookupSalesId(FormStringControl _ctrl,
2: ptnInvoiceAccount _InvoiceAccount)
3: {
4:
5: SysTableLookup sysTableLookup = SysTableLookup::newParameters(tablenum(SalesTable), _ctrl);
6: Query query = new Query();
7: QueryBuildDataSource qbds;
8: QueryBuildRange SalesTableFilter;
9: ;
10: sysTableLookup.addLookupfield(fieldnum(SalesTable, SalesId),true);
11: sysTableLookup.addLookupfield(fieldnum(SalesTable, CreatedDate));
12: qbds = query.addDataSource(tablenum(SalesTable));
13: qbds.addRange(fieldnum(SalesTable, InvoiceAccount)).value(queryValue(_InvoiceAccount));
14: qbds.addRange(fieldnum(SalesTable, SalesStatus)).value(queryValue(SalesStatus::Invoiced));
15: qbds.addRange(fieldnum(SalesTable, SalesType)).value(queryValue(SalesType::Sales));
16: qbds.addSortField(fieldNum(SalesTable,SalesId), SortOrder::Descending);
17: sysTableLookup.parmQuery(query);
18: sysTableLookup.performFormLookup();
19: }
20:
In line 5 I set up the sysTableLookup to use the SalesTable.
In line 10 & 11 I add the SalesID and CreatedDate to the visible fields when you click the drop down box in Dynamics Ax. Line 10 also sets the SalesID as the return item.
Line 12 adds the sales table to the datasource and lines 13 thru 15 add the where clause for the query.
Line 16 sorts the drop down by descending order of sales id.
Just add a static method to the table where you want a special lookup.
Then go to the form where you want the special lookup, find the datasource
Expand this to get to the field you want to perform the custom lookup
Right click on “Methods” and choose override method, “lookup”
comment out the super call and new method should look like this..
1: public void lookup(FormControl _formControl, str _filterStr)
2: {
3: ;
4: //super(_formControl, _filterStr);
5: ptnCreditDebitMemoLine::lookupSalesId(_formControl, ptnCreditDebitMemoLine.InvoiceAccount);
6: }
Line 5 is the call to the static method we created earlier.
That is it, now wherever you have that field on your form, either in a grid or on a tab, it will display your custom drop down.
No comments:
Post a Comment