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

CoC on table CustCollectionLetterJour

(0) ShareShare
ReportReport
Posted on by

Hi guys,

Wants to know if I add a CoC class on table CustCollectionLetterJour, and the method I want to add is actually the "insert" method, can I do that without specifying "next insert()" ?

There is no explicit "insert" method in this table in AOT but of course every table has it. But if I specified "next insert()" in my CoC, during debug, I hit error "DuplicateKeyException was unhandled by usercode".

Just worried if I didn;t include "next insert()" will the insertion ran normally as it should with addition of my extension ?

Please advice.

Thanks,

I have the same question (0)
  • WillWU Profile Picture
    22,361 on at

    Hi Voltes,

    You could use the OnInserted event handler, and copy the event handler method in a new class like this:

      [DataEventHandler(tableStr(CustCollectionLetterJour), DataEventType::Inserted)]

       public static void CustCollectionLetterJour_onInserted(Common sender, DataEventArgs e)

       {

          CustCollectionLetterJour custCollectionLetterJour=sender as CustCollectionLetterJour;

       }

  • VoltesDev Profile Picture
    on at

    Hi Will,

    Yes, I thought the same. But apparently hit other error like this :

    Severity Code Description Project File Line Suppression State

    Error Cannot generate chain of command subscription inialization code for 'CustCollectionLetterJour'.'insert'.  Exception: 'Object reference not set to an instance of an object.' at:    at IKVM.Reflection.Emit.ModuleBuilder.GetTypeToken(Type type)

      at IKVM.Reflection.Emit.ILGenerator.Emit(OpCode opc, Type type)

      at Microsoft.Dynamics.AX.Framework.Xlnt.ILGenerator.ILGeneratorPass3Worker.EmitChainOfCommandSubscriptionsCode(Parameters parameters, IXppcMetadataProvider metadataProvider, NetModuleNameByTypeName netModules, FileRollbackHandler fileRollbackHandler, IDiagnosticSink diagnosticsHandler). CustCollectionLetterJour 0

    Which I'm not sure why it is still saying chain of command.

    I tried to Clean solution, Rebuild, or close and open Visual Studio again, but the error persist.

    Thanks

  • André Arnaud de Calavon Profile Picture
    301,025 Super User 2025 Season 2 on at

    HI VoltesDev,

    Using CoC, you always have to use the "next insert()" command. This is required. What is the exact coding you used in the method? Can you share the contents of that method?

  • Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    If you didn't call next insert(), no insert would happen, because next insert() is the place where you're calling the kernel logic to actually do all the stuff.

    The error message means that you're inserting a record with a key that already exists in the table.

  • Verified answer
    WillWU Profile Picture
    22,361 on at

    Hi Voltes,

    Please try to do a full build in your model and the Application Suite model.

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    As mentioned above, duplicate key exception occurs if you try to insert a record that already exists on the table (based on fields in any unique index). It has nothing to do with chain of command.

    You have to call "next" because that calls the actual underlying insert() method, without it nothing would be inserted.

    If you need help with your code, could you please share it?

  • VoltesDev Profile Picture
    on at

    Hi all,

    Thank you for all the advice. And also the confirmation that I should include Next method.

    I switch by using Post Even Handler, btw. That when the 2nd error happened.

    For the error, it solved after Full Build. My guess is during open the base table I accidentally change something, although I cannot save it, and tried to restore it even, maybe something in memory already changed.

    Issue solved.

    Thanks,

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 611 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans