Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

Error Chain of command method must contain one next call.

(1) ShareShare
ReportReport
Posted on by 3,024
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:
  • Suggested answer
    Martin Dráb Profile Picture
    Martin Dráb 230,479 Most Valuable Professional on at
    Error Chain of command method must contain one next call.
    The methods already exist, you're just using a wrong class. You'll find them in CurrencyExchange class, not CurrencyExchangeHelper class.
  • Waed Ayyad Profile Picture
    Waed Ayyad 6,408 Super User 2024 Season 2 on at
    Error Chain of command method must contain one next call.
    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

     

  • Shabir Ahmad Profile Picture
    Shabir Ahmad 3,024 on at
    Error Chain of command method must contain one next call.
    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
  • Martin Dráb Profile Picture
    Martin Dráb 230,479 Most Valuable Professional on at
    Error Chain of command method must contain one next call.
    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.
  • Suggested answer
    Waed Ayyad Profile Picture
    Waed Ayyad 6,408 Super User 2024 Season 2 on at
    Error Chain of command method must contain one next call.
    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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,409 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,479 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans