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)


No comments:

Post a Comment

Run AX report using X++

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