Thursday 27 June 2019

To find the string all files in AOT


To find the string all files in AOT, use below command

K:\AosService\PackagesLocalDirectory\DynaCrane>findstr /i /l /n /s /c:"InternalTask" *.xml

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.

Friday 21 June 2019

Get Purchase Order Financial Dimensions Using X++

Public void run()
{
    Di_FinancialDimensionsTmp         Di_FinancialDimensionsTmp;
    PurchLine                                        purchLine;
    PurchTable                                      purchTable;
    DimensionAttribute                        dimensionAttribute;
    DimensionAttributeValue               dimensionAttributeValue;
    Dimensionattributevalueset            dimensionattributevalueset;
    DimensionAttributeValueSetItem   dimensionAttributeValueSetItem;


    while select PurchLine
    {
     while select dimensionAttributeValueSetItem
        where dimensionAttributeValueSetItem.DimensionAttributeValueSet == purchLine.DefaultDimension
          join dimensionAttributeValue
            where dimensionAttributeValue.RecId == dimensionAttributeValueSetItem.DimensionAttributeValue
              join  dimensionAttribute
                where dimensionAttribute.RecId == dimensionAttributeValue.DimensionAttribute
     {
        switch (DimensionAttribute.Name)
        {
            case BusinessUnit     :
            Di_FinancialDimensionsTmp.BusinessUnit = dimensionAttributeValueSetItem.DisplayValue;
            break;
            case CostCenter :
            Di_FinancialDimensionsTmp.CostCenter    = dimensionAttributeValueSetItem.DisplayValue;
            break;
            case Department :
            Di_FinancialDimensionsTmp.Department    = dimensionAttributeValueSetItem.DisplayValue;
            break;
            case ItemGroup :
            Di_FinancialDimensionsTmp.ItemGroup     = dimensionAttributeValueSetItem.DisplayValue;
            break;
            case Project:
            Di_FinancialDimensionsTmp.Project         = dimensionAttributeValueSetItem.DisplayValue;
            break;
        }
        Di_FinancialDimensionsTmp.LineNumber = PurchLine.LineNumber;
     }
    Di_FinancialDimensionsTmp.Purchid = purchLine.PurchId;
    Di_FinancialDimensionsTmp.insert();
}

Refresh called form once button clicked is executed.

class WHSContainerTableFormEventHandler
{
   
    [FormControlEventHandler(formControlStr(WHSContainerTable, CreateNewCarrierLabel), FormControlEventType::Clicked)]
    public static void CreateNewCarrierLabel_OnClicked(FormControl sender, FormControlEventArgs e)
    {
        sender.formRun().dataSource().research(true);

    }

}