Sunday, 23 June 2019

Filterning List Page

1. Filter ListPage for Created by Current User



At times a client will request that users only view the records they created from a specific table. A good example for this scenario is with purchase Requisition, all users need not see what other employees are requesting for purchase. Fortunately this is catered for out of the box, but for other tables a customization needs to be made.
prforme

As a consultant you may be tasked to do the customization in another module,
To demonstrate i will use the Purchase Requisition form so that you can refer from your system ;
Go to AOT Tables and navigate to the PurchReqTable Table, the first thing to note is the Table property created by set to yes which is the field we will use to filter,
createdby

Next navigate to the queries group, Navigate to the PurchReqTableCreatedByMe query  and on the add a filter for the created by field to only show records created by the current user.
querycb

On AOT now navigate to menu Items group, display menu items. On the PurchReqPreparedByMe menu item go to the Query property. add the  PurchReqTableCreatedByMe query and save all.
menuitemq

Now going back to the Area Page and clicking the menu item link Purchase Requisitions Created by me, will show a filtered list of only Purchase Requisitions created by the current user.
============================================================

2. Adding Custome filter on Listpage


magine you want a filter on a list page say planned orders list page. Filter works on the order date and shows order due today or all. It has two values in the selection Today/All. Its not that straightforward as it may seem as it is a list page. On a normal AX form, its much easier.
A number of steps required to achieve this.
1. Add the custom filter to the list page. Note the filterExpression, its a call to method we create in next step. Also you need an enum and an EDT based off the enum, EDT is selected in the properties as well.
2. SysQueryRangeUtil
Add a method to the SysQueryRangeUtil.
3. Interaction class
List pages use the interaction classes for logic. We need to customize 2 methods in the ReqTransPOListPageInteraction.
In method initializing, after super(), add this
   customFilter = SysEPCustomFilter::construct(formStr(ReqTransPOListPage));  
   customFilter.load();  
   customFilter.setInitialFilterControlValue(formControlStr(ReqTransPOListPage, yourFilter), 0);  
Note: customFilter.load() will reload the last saved selection in your filter. In case, you want a specific enum selection everytime, comment out this line.
In method initializeQuery, before super(), add this
Note the call to method in SysQueryRangeUtil
   if (this.listPage().listPageArgs().parameters())  
   {  
     reqPOFilterEnum = customFilter.getFilterControlValue(formControlStr(ReqTransPOListPage, yourFilter));  
     SysQuery::findOrCreateRange(_query.dataSourceTable(tableNum(ReqPO)), fieldNum(ReqPO, ReqDateOrder)).value(SysQueryRangeUtil::xxxReqPOFilter(reqPOFilterEnum));  
   }  
4. Your list page

=================================================

3. Filter Purchtable listpage based on Dimension assigned to worker for current user id

i) Add one enum item -'WorkerDimensions' to Enum - 'PurchTableListPage'
ii) Create new menu item -PurchTableListPage_WorkeDimensions pass  Enum type parameter -'PurchTableListPage', Enum parameter- 'WorkerDimensions'
iii) Modify method PurchTableListPageInteraction\initializeQuery
 //bju
     else if (this.getListPageType() == PurchTableListPage::WorkerDimensions)
    {
         qbds = _query.dataSourceTable(tableNum(PurchTable));
        qbds.clearDynalinks();
        qbds = _query.dataSourceTable(tableNum(PurchTable)).addDataSource(tableNum(PurchLine));
        qbds.relations(true);
        qbds.joinMode(JoinMode::ExistsJoin);
       
        qbds.addRange(fieldNum(PurchLine,DefaultDimension)).value(queryValue(HcmWorker::find(DirPersonUser::currentWorker()).getDefaultDimension()));
    }
    //bju

iv) Add new menu item at required position in ax.

No comments:

Post a Comment