Showing posts with label D365 for Finance and operations. Show all posts
Showing posts with label D365 for Finance and operations. Show all posts

Wednesday, 1 September 2021

Converting amount in words using X++

During SSRS report development in ax sometimes we have a requirement to convert the amount into words, unfortunatly in SSRS report level, there is no such method available. You have to write VB code to do it.

The more simple solution would be to write the code in the report data provider class to perform conversion and store it into a field that can easily be used in the SSRS report

Here is the code you can convert the amount in words in Ax / D365FO 

private String255 AmountInWords(real _amount)

{

     int             amount;

     String255             amount2Words;

    amount       = real2int(round(_amount , 1));

    amount2Words = Global::numeralsToTxt(amount);

    amount2Words = subStr(amount2Words,5,strLen(amount2Words)-4);

    amount2Words = subStr(amount2Words,strLen(amount2Words)-10,-strLen(amount2Words));

    amount2Words = (amount2Words) + ' Only';

    return amount2Words;

}

there is a builtin function available in Global class as well, you can try this as well

Global::numeralsToTxt(Amount)


Tuesday, 31 August 2021

Get item Category hierarchy using X++ in Ax / D365FO

Here you can find the X++ code to get complete item Category hierarchy using X++ in Ax

Static void main(Args args)
{ 
ItemId itemId = "MT0001";
EcoResProductCategory EcoResProductCategory;
EcoResCategory EcoResCategory,EcoResCategoryNext;
EcoResCategoryId parentCategory;
List li = new List(Types::String);
ListEnumerator enumer;

select * from EcoResCategory
join RecId from EcoResProductCategory
where EcoResCategory.RecId == EcoResProductCategory.Category
&& EcoResProductCategory.Product == InventTable::find(itemId).Product;
parentCategory = EcoResCategory.ParentCategory;
li.addStart(EcoResCategory.Name);

while (parentCategory)
{
    select * from EcoResCategory
        where EcoResCategory.RecId == parentCategory;
    //&& EcoResCategory.ParentCategory != 0;
        parentCategory = EcoResCategory.ParentCategory;
        li.addStart(EcoResCategory.Name);
}

enumer = li.getEnumerator();

while (enumer.moveNext())
{
    info(enumer.current());
}
}

Run AX report using X++

       Args                     args;      ReportRun          report;     salesLineProductPartProd salesLineProductPartProdLocal;     ;     ...