Alfasith AX

Alfasith AX
اللَّهُمَّ انْفَعْنِي بِمَا عَلَّمْتَنِي، وَعَلِّمْنِي مَا يَنْفَعُنِي، وَزِدْنِي عِلْمًا

Friday, May 10, 2024

How to invoke and iterate List as Contract methods in AX 2012/ D365

Hi,

Public void performContractIterate(ClassContainsListAsContract    _ListCarryClass)
{
List contractFieldList = new List(Types::Class);
ResResourceCategoryDataContract    resourceCategoryDataContract =  new ResResourceCategoryDataContract();
contractFieldList = _ListCarryClass.parmCustomFields();
/*
// List Iterator are not recorded for mutiTier data flow example integrations with other Apps like PowerApps or APIs
ListIterator        literator = new ListIterator(contractFieldList );
while (literator.more())
{
resourceCategoryDataContract= literator.value();
if(resourceCategoryDataContract.parmId() == 1 )
{
resourceCategoryId = resourceCategoryDataContract.parmValue();
}
literator.next();
}
*/
//Traverse the same _ListCarryClass using an enumerator
ListEnumerator   enumerator = contractFieldList .getEnumerator();
while(enumerator.moveNext())
{
resourceCategoryDataContract= enumerator.current();
switch (resourceCategoryDataContract.parmId())
{
case 1:
resourceCategoryId = resourceCategoryDataContract.parmValue();
break;
}
}
//<Perform your action based on the iterator value fetched>
}
_________________________________________________________________________________

Similar example.

DimensionValueService service = new DimensionValueService();
DimensionContract dimensionContract = new DimensionContract();
DimensionValueContract dimensionValueContract;
DimensionValue dimensionValue;
List dimensionValueContractList;
ListIterator contractorIterator;
 
;
  
dimensionContract.parmDimensionName(#DimName);
dimensionValueContractList = service.getDimensionValues(dimensionContract);
contractorIterator = new ListIterator(dimensionValueContractList);
ListEnumerator contractorEnumerator = dimensionValueContractList.getEnumerator();
    
    while(contractorEnumerator.moveNext())
    {
        dimensionValueContract = contractorEnumerator.current();
        dimensionValue = dimensionValueContract.parmValue();
        {
            info(strFmt("%1", dimensionValue));
        }
    }

Regards,

Wednesday, April 24, 2024

How find size of recordsortedlist in D365/AX 2012

Hi,


This is the continuity of the previous article where we are now getting the size of recordsortedlist .


if(recordsortedlist.len() >1)
{
    print("Given recordsortedlist is bigger than 1");
}

Thanks,

Group By and Max(Date) in SQL / disticnt (GROUP BY with MAX(DATE) [duplicate] )

 Hi, Train    Dest      Time 1        HK        10:00 1        SH        12:00 1        SZ        14:00 2        HK        13:00 2        SH...