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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Condition put in CoC in D365FO

(3) ShareShare
ReportReport
Posted on by 276
Dear team,
 
Can we put condition in CoC? I mean if condition is true then only CoC will execute else not 
 
If not possible then if any workaround is there?
 
Please give me the thoughts. thanks!
Categories:
I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    238,740 Most Valuable Professional on at
    No, it's not possible. CoC means that you create an extension class and extend a method; there is no way how to make the existence of a class or a method conditional. It's either there or not.
     
    But you can put conditions to the method code.
     
    Maybe you mean whether you can conditionally call the base method (with the next keyword). It's not normally possible, unless the base method is explicitly marked as replaceable.
  • Suggested answer
    Mohamed Amine Mahmoudi Profile Picture
    26,779 Super User 2026 Season 1 on at
     
    It is not recommended to ignore the call to next, but you can do so with an exception !
     
    Best regards,
  • CU10121822-0 Profile Picture
    276 on at
    Hi, I tried in below way:
     
    [ExtensionOf(classStr(SalesTable))]
    final class SalesTable_Extension
    {
        public void update()
        {
            try
            {
                // Pre-logic with condition
                if (this.CustAccount == 'CUST001')
                {
                    info("Before update: Special customer logic");
                }
                
                next update();
    
                // Post-logic with condition
                if (this.SalesStatus == SalesStatus::Invoiced)
                {
                    info("After update: Sales order invoiced");
                }
            }
            catch (Exception::Error)
            {
                error("Error occurred while updating SalesTable");
                throw; // always rethrow in CoC
            }
        }
    }
     
    So, here what I understood, the condition is returned TRUE or False, it's doesn't matter, CoC will execute always.
     
    am I correct?
  • Anton Venter Profile Picture
    20,629 Super User 2026 Season 1 on at
    Yes, once created / defined, the CoC will always be called by the system. Adding conditions in the your extension code is probably the solution you are after.
  • CU10121822-0 Profile Picture
    276 on at
    Thanks Anton,
     
    Then put the condition in CoC, will be use less.
    Am I correct ?
  • Anton Venter Profile Picture
    20,629 Super User 2026 Season 1 on at
    Not sure if I follow you and I might be on a wrong track here. That depends on the code your CoC code. If you are worried about performance, the fact the CoC code is called by the system does not really add much performance overhead on it's own provided there is no database query / update etc. or other time consuming code like calling a web service etc. So, if you have a CoC with a condition that only executes your logic when necessary, it does not really add noticeable overhead.
     
    What adds performance overhead is querying or updating the database, or calling other things like web services etc..
  • André Arnaud de Calavon Profile Picture
    303,126 Super User 2026 Season 1 on at
    Hi,
     
    A small clarification. Your CoC coding will be always executed. The next() call is mandatory. You can add coding before and after the next() command.
     
    You now have conditions in your X++ coding. The condition will be evaluated and will be true or false. So, in your example, if the customer account number is CUST001, then you will get your info message, whereas for any other customer, the message is skipped.
     
    If this is what you meant by a condition, then this is not useless. In many cases, I used such condition in X++ coding on CoC methods. I think that is also what Anton wanted to say in the message just after your code example.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 590 Super User 2026 Season 1

#2
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 349

#3
Diego Mancassola Profile Picture

Diego Mancassola 263

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans