web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Error Chain of command method must contain one next call.

(3) ShareShare
ReportReport
Posted on by 3,110
Hi experts,
I want to add 4 new methods to Standard class "CurrencyExchangeHelper"  . I already tried by getting error "Error Chain of command method must contain one next call."  I have allready checked some posted questions but didn't get it could you please tell me how to do it below are 4 methods 
 
public static Amount roundWithRuleTypeCurrencyTable(Amount _amount, Currency _currency, CurrencyRoundingRuleType _currencyRoundingRuleType)
{
    Amount result;
    if (_amount == 0)
    {
        return 0;
    }
    switch (_currencyRoundingRuleType)
    {
        case CurrencyRoundingRuleType::Amount:
            result = CurrencyExchangeHelper::roundWithRule(
                _amount,
                _currency.RoundingPrecision,
                RoundOffType::Ordinary);
            break;
        case CurrencyRoundingRuleType::Price:
            result = CurrencyExchangeHelper::roundWithRule(
                _amount,
                _currency.RoundOffPrice,
                _currency.RoundOffTypePrice);
            break;
        case CurrencyRoundingRuleType::PurchaseOrder:
            result = CurrencyExchangeHelper::roundWithRule(
                _amount,
                _currency.RoundOffPurch,
                _currency.RoundOffTypePurch);
            break;
        case CurrencyRoundingRuleType::SalesOrder:
            result = CurrencyExchangeHelper::roundWithRule(
                _amount,
                _currency.RoundOffSales,
                _currency.RoundOffTypeSales);
            break;
        // <GJP>
        case CurrencyRoundingRuleType::AssetDep_JP:
            result = CurrencyExchangeHelper::roundWithRule(
                _amount,
                _currency.RoundOffAssetDep_JP,
                _currency.RoundOffTypeAssetDep_JP);
            break;
        // </GJP>
        default:
            throw error(Error::wrongUseOfFunction(funcname()));
    }
    return result;
}
 
 
public static Amount roundWithRuleType(Amount _amount, CurrencyCode _currency, CurrencyRoundingRuleType _currencyRoundingRuleType)
{
    Currency currency;
    if (_amount == 0)
    {
        return 0;
    }
    if (_currency)
    {
        currency = Currency::find(_currency);
    }
    else
    {
        currency = Currency::find(Ledger::accountingCurrency());
    }
    return CurrencyExchangeHelper::roundWithRuleTypeCurrencyTable(_amount, currency, _currencyRoundingRuleType);
}
3
 
public static Amount roundWithRule(Amount _amount, RoundOff _roundOffAmount, RoundOffType _roundOffType)
{
    RoundOff roundOffAmountLoc = _roundOffAmount;
    Amount result;
    if (_amount == 0)
    {
        return 0;
    }
    switch (_roundOffType)
    {
        case RoundOffType::Ordinary:
            if (!roundOffAmountLoc)
            {
                roundOffAmountLoc = 0.01;
            }
            result = round(_amount, roundOffAmountLoc);
            break;
        case RoundOffType::RoundDown:
            if (!roundOffAmountLoc)
            {
                roundOffAmountLoc = 1.0;
            }
            // round to zero since from a financial standpoint that's what
            // we mean by rounding down
            result = roundZero(_amount, roundOffAmountLoc);
            break;
        case RoundOffType::RoundUp:
            if (!roundOffAmountLoc)
            {
                roundOffAmountLoc = 1.0;
            }
     
            if (_amount >= 0)
            {
                result = roundUp(_amount, roundOffAmountLoc);
            }
            else
            {
                result = roundDown(_amount, roundOffAmountLoc);
            }
            break;
        default:
            throw error(Error::wrongUseOfFunction(funcname()));
    }
    return result;
}
4
public static Amount round(Amount _amount, CurrencyCode _currency)
{
    return CurrencyExchangeHelper::roundWithRuleType(
        _amount,
        _currency,
        CurrencyRoundingRuleType::Amount);
}
 
 
Thanks and Regards,
Shabir Ahmad
Categories:
I have the same question (0)
  • Suggested answer
    Waed Ayyad Profile Picture
    9,039 Super User 2025 Season 2 on at
    Hi,
     
    In Chain of Command, if you make an extension of standard method, you should use next() keyword before or after your logic, so in your code can you tell me if any of the four methods that you added exist in the standard method?
     
    For Example, if amount method is a standard method, then you should write the following code:
    public static Amount round(Amount _amount, CurrencyCode _currency)
    {
        Amount roundedAmount = next round(_amount,_currency);
    
        roundedAmount = CurrencyExchangeHelper::roundWithRuleType(
                       _amount,
                       _currency,
                        CurrencyRoundingRuleType::Amount);
          
        return roundedAmount;
    }

     
    To read more about COC, Check the following link:
    https://dynamics365musings.com/chain-of-command-class-methods/
     
     

    Thanks,

    Waed Ayyad

    If this helped, please mark it as "Verified" for others facing the same issue

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at
    What's the whole point of your customization? It looks like you merely copied methods from CurrencyExchange, which gives you no benefit. You can simply use the standard methods instead of your own.
     
    If you think you need an extension, please show us the header of your class. It sounds to me like if you;re extending CurrencyExchange, not CurrencyExchangeHelper.
     
    Moved from Integration, Dataverse, and general topics forum.
  • Shabir Ahmad Profile Picture
    3,110 on at
    Thanks to both of you ,
     
    Actually, the methods which i have added here is exist in dynamics ax 2012. But in D365 FO "CurrencyExchangeHelper" Class these methods are not here i just tried to bring from ax 2012 to d365 FO. These methods are not existing methods. it is actually new in d365 FO.
     
    Thanks and Regards,
    Shabir Ahmad
  • Waed Ayyad Profile Picture
    9,039 Super User 2025 Season 2 on at
    Hi,
     
    Does CurrencyExchangeHelper class extend another class? Can you show us the error message that you received and your code from the beginning?
     

    Thanks,

    Waed Ayyad

     

  • Verified answer
    Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at
    The methods already exist, you're just using a wrong class. You'll find them in CurrencyExchange class, not CurrencyExchangeHelper class.
  • Shabir Ahmad Profile Picture
    3,110 on at
    Hi ,
  • Shabir Ahmad Profile Picture
    3,110 on at
    Hi,
    these screen shots are from D365 FO 
  • Shabir Ahmad Profile Picture
    3,110 on at
  • Verified answer
    Layan Jwei Profile Picture
    8,118 Super User 2025 Season 2 on at
    Hi Shabir,

    "CurrencyExchangeHelper" class extends "CurrencyExchange" class, which means it inherits all of it's methods
     
    if you go inside the class "CurrencyExchange" then you will see that those methods are already there, there is no need to add them
     
    so all you need to do is to call one of the methods like this:
    CurrencyExchange::round(123, "GBP");
    Thanks,
    Layan Jweihan
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
  • Shabir Ahmad Profile Picture
    3,110 on at
    Thanks to both of you 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 451 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 428 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans