Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / Override Insert() meth...
Finance forum
Suggested answer

Override Insert() method into a table Dynamics 365 F&O

Posted on by 440

Hi,

I would like to know how to override a table method for example Insert() method using extension.

Also i am trying to add aosValidateInsert() and aosValidateUpdate() to an extension class for the same table but i am getting an error that it is marked for internal use only:

So, how can i add these methods to the table!!

6562.err.png

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: Override Insert() method into a table Dynamics 365 F&O

    No, you can't create derived classes of tables or forms.

    Class hierarchies are not supported on tables and forms, only on classes.

  • Peter Samir Profile Picture
    Peter Samir 440 on at
    RE: Override Insert() method into a table Dynamics 365 F&O

    Thanks,

    This method into table (WorkflowWorkItemTable), I tried to right click and view code then it opened (public class WorkflowWorkItemTable extends common) that contains all default methods.

    Can i create a derived class, override this method and do not call supper. Then using CoC extend constructor to instantiate derived class instead of original?

    community.dynamics.com/.../318273

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: Override Insert() method into a table Dynamics 365 F&O

    Insertion will be done in all cases. Like you have been told many times already, you can't skip the execution of the standard logic by extending it.

    However in ValidateWrite you can add your own checks after calling next(), and return false if your custom validations fail. If the validation fails, the data will not be inserted. But only if the "inserter" calls validateWrite (it's always called when data is inserted/updated from forms, but in x++ it's possible to not call it).

  • Peter Samir Profile Picture
    Peter Samir 440 on at
    RE: Override Insert() method into a table Dynamics 365 F&O

    Hi Nikolaos,

    You said that I can't prevent the standard code. Do you mean that the insertion will be done in all cases??

    There is no way to set a condition?? As I think if I moved my code to validateWrite I will have the same problem as I will not able to set a condition too.

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: Override Insert() method into a table Dynamics 365 F&O

    You need to refactor your code and reimplement it with Chain of Command.

    In my opinion all validations (that might prevent the insertion) belong to validateWrite, not insert method.

    But you can also use Chain of Command with the insert method, and update/delete the record after it's been inserted (and populated with the standard values).

    You can't prevent the standard code from being executed, but you can do your magic before or after it.

  • Peter Samir Profile Picture
    Peter Samir 440 on at
    RE: Override Insert() method into a table Dynamics 365 F&O

    Hi,

    Thanks for your replies.

    Actually, I am upgrading from AX 2012 to D365 FO. I have a Table\Insert( ) method with a customizations that need to be migrated.

    The original method is as follow:

       public void insert()

       {

           this.Subject = SysEmailMessage::resolveUrls(this.Subject, false);

           this.Description = SysEmailMessage::resolveUrls(this.Description, false);

           super();

       }


    The customized code into AX 2012 (highlighted in red) that need to be migrated is as follow:

    public void insert()
    {
        boolean Insert=true;
        PurchReqLine PurchReqLine;

        this.Subject = SysEmailMessage::resolveUrls(this.Subject, false);
       
        select firstOnly Category from workflowTable
        where workflowTable.ConfigurationId == this.ConfigurationId;

       
       if (workflowTable.Category != WorkflowInstanceCategory::LineItemWorkflow)
        {
            this.Description = SysEmailMessage::resolveUrls(this.Description, false);
        }


        if(this.RefTableId ==  tableName2id('PurchReqLine'))
        {
            select * from PurchReqLine where PurchReqLine.RecId==this.RefRecId;
            if(PurchReqLine && PurchReqLine.RequisitionStatus==PurchReqRequisitionStatus::Rejected)
            {
                this.Status=WorkflowWorkItemStatus::Completed;
                this.Type=WorkflowWorkItemType::WorkItem;
                Insert=false;
            }
        }

        if(Insert)
          super();
    }

  • Suggested answer
    BrandonSA Profile Picture
    BrandonSA 1,667 on at
    RE: Override Insert() method into a table Dynamics 365 F&O

    Hi Peter

    I would take note of everything everyone else has said here.

    As for chain of command, you don't use super, you use next as described here:

    https://docs.microsoft.com/en-us/dynamics365/unified-operations/dev-itpro/extensibility/method-wrapping-coc

    You're basically looking at something like this:

    [ExtensionOf(tablestr(YourTable))]
    final class YourTable_Extension
    {
        public void yourMethod()
        {
            next yourMethod();
            //...
        }
    }

    Hope this helps

  • Suggested answer
    Joris dG Profile Picture
    Joris dG 17,775 on at
    RE: Override Insert() method into a table Dynamics 365 F&O

    Is there a specific reason you can't use validateWrite(), insert() or update() ?

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: Override Insert() method into a table Dynamics 365 F&O

    You can't override the standard table / form methods in D365FO.

    You can hook into standard events such as onInserting. Or use Chain of Command on the methods (not sure if all framework table methods are supported for CoC yet or not).

  • Suggested answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 290,252 Super User 2024 Season 2 on at
    RE: Override Insert() method into a table Dynamics 365 F&O

    Hi Peter,

    If you have a business requirement to override the aosValidateInsert and/or aosValidateUpdate methods, you can create extensibility requests for it. First check if the latest release (10.0.1 or 10.0.2) has the same issue with having these methods marked as internal only.

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,252 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,089 Super User 2024 Season 2

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans