In Microsoft Dynamics AX 2012, ListPages are more restricted from customization than in prior versions of AX. Primary reason for the restriction is so that the list pages maintain compatibility with Enterprise Portal. Recently a customer had a requirement where the filter needs to be available on the list page and only on the client side. I spent quite some time searching for a solution and thought I’d share my workaround here – This post will outline how to create a customized filter on the Released Product list page.
The Requirement: quickly find Released Product by External Item number and display the Released Product Number(s) on the Released Products List page.
The Solution: Since we are looking for data not part of any DataSource on the original query – and due to some join complexities, customizing the existing query was also not an option, X++ became the last option. (As you may or may not know, external item data is stored in the CustVendExternalItem Table.) Microsoft specifies for developers to change the *LPInteraction class, however I have to date not found any concrete examples for using the class to manipulate the list pages. For this example we will modify the Released Product List Page by overriding the modified method on a filter field.
Here is how:
1. We need to allow overriding of methods on fields on the form (which by default is not allowed on Forms of FormTemplate: ListPage). Navigate to the AOT –> Forms –> EcoResProductPerCompanyListPage –> Designs –> Design –> Group:Filter –> Properties –> Display Target and select “Client”. Note this means that the filters will only be visible in the AX client and not via EP. This will also allow us to actually override the “modified” method on the filter form. Ensure that the filter is Visible, DisplayTarget is set to Client and the Caption, FrameOptionButton and OptionValue can be set as needed/desired.
2. Create a new field under the filter section, ensure that AutoDeclaration is set to “Yes” and that the proper data type is selected. In this case the ExtendedDataType should be “ExternalItemId”
3. Override the “modified” method on the Field. Note if you are unable to override any method then you have not completed step number 1 above.
3. Paste code below to filter by the external customer/vend ItemId. Note: there are many different ways to create the desired result other than below, notably the “QueryFilter” object is another alternative.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
</pre> public boolean modified() { boolean ret; QueryBuildRange qbr; QueryRun queryRun; Query query; QueryBuildDataSource qbds; SysTableLookup lookup; ItemId itemId; CustVendExternalItem custVendExternalItem; ret = super(); if ( this .valueStr()) { query = new query(); qbds = query.addDataSource(tableNum(CustVendExternalItem)); qbr = qbds.addRange(fieldNum(CustVendExternalItem, ExternalItemId)); qbr.value(queryValue( this .valueStr())); queryRun = new QueryRun(query); while (queryRun.next()) { custVendExternalItem = queryRun. get (tableNum(custVendExternalItem)); itemId = custVendExternalItem.ItemId; break ; } // if we found a match in the external item table show it if (itemId) { InventTable_ds.queryBuildDataSource().addRange(fieldNum(InventTable, ItemId)).value(itemId); InventTable_ds.executeQuery(); } } else { InventTable_ds.queryBuildDataSource().clearRanges(); InventTable_ds.executeQuery(); } return ret; } |
4. One nice thing about the filter Group is that it includes a display type, I have selected “Hide” which allows a user to hide it if they do not want to see/use the specific filter with minimal screen real-estate being consumed. Run an X++ compile on the form and Incremental CIL compile and the Released Product form should look like below.
5. For our example I have added a an external item Id “S1CTestItem” in the Contoso environment. Let’s see what product this item corresponds to. Just type in the External Item Id and hit Tab or enter.
The form runs the query and displays the result.
6. Just to confirm, we go to the “External Item Description” form and as you can see everything checks out.
That’s it! As you can see this is the basic framework for customizing the list page form if you cannot change the Query object or are not able to pass the necessary parameters to the LPInteraction class.