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

Learn CoC : Order

(0) ShareShare
ReportReport
Posted on by

Hi Guys,

Just starting to learn CoC. Currently am a bit confuse of the order of these CoC, about who's goes first and then which one is next. I' creating 2 CoC classes like this :

1st class :

[ExtensionOf(tablestr(SalesTable))]
final class SalesTableTable_Extension
{

public void delete()
{
SalesTable salestablelocal;

next delete();

select firstonly salestablelocal where salestablelocal.salesid == this.salesId;
if (salestablelocal)
{
info(SalesTablelocal.SalesId);
}
else
{
info(strFmt("Sucessfully deleted %1", DateTimeUtil::getSystemDateTime()));
}
}

}

And 2nd class:

[ExtensionOf(tablestr(SalesTable))]
final class SalesTableTable_2_Extension
{
public void delete()
{
SalesTable salestablelocal;

next delete();

select firstonly salestablelocal where salestablelocal.salesid == this.salesId;
if (salestablelocal)
{
info(SalesTablelocal.SalesId);
}
else
{
info(strFmt("Okay, it is deleted %1", DateTimeUtil::getSystemDateTime()));
}
}

}

And when I test, create New Sales Order and delete it, it looks like the 2nd class goes first. Is it true that in CoC the last CoC class will be executed first, but how to know which one is the last if for example many developer are in our environment ?

Also in Micorosft docs : https://docs.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/extensibility/method-wrapping-coc

there is this statement : 

The system randomly runs one of these methods, such as the doSomething method of the BusinessLogic1_Extension class. When the call to the next doSomething method occurs, the system randomly picks another method in the CoC. If no more wrapped methods exist, the system calls the original implementation.

So it is randomly or took the last one ? but also in that statement, after "randomly", if no more then call the original. Does it mean then the original Delete method will be executed ? but my CoC class resulted the record already deleted, means the original already finished firstly.

Thanks,

I have the same question (0)
  • Suggested answer
    André Arnaud de Calavon Profile Picture
    301,141 Super User 2025 Season 2 on at

    Hi Voltes,

    You can't control the execution order of CoC. This can be different per environment. When you tested it in a DEV environment, it might behave different in the production environment.

    The only thing you can manage is calling the Next() statement before or after your coding. Try to put "next delete()" after your x++ coding to see the difference.

  • Verified answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    Having many developers in your project doesn't mean that everyone should develop their own CoC class. Instead everyone should work with the same CoC class, and then you can easily determine which code should be executed first.

    In the delete method, the record will not exist after calling next() because the next() will eventually call the delete method of the table, and the super() call in that method will delete the record.

  • VoltesDev Profile Picture
    on at

    Ok,

    Now I understand, Thank you both.

  • Suggested answer
    Joris dG Profile Picture
    17,775 on at

    The original method will always be at the end of the next() chain.

    As far as CoC, it's not exactly "random" of course. The point is that any update to F&O, a new code deployment, potentially even a restart, etc. any of those things could change the order in which the chain is executed - so you cannot depend on the ordering and need to code defensively.

  • VoltesDev Profile Picture
    on at

    Hi Joris,

    Noted. Thanks for this.

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
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 429 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans