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 :
Dynamics 365 Community / Forums / Finance forum / Override Insert() meth...
Finance forum

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

(0) ShareShare
ReportReport
Posted on by 446

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
    André Arnaud de Calavon Profile Picture
    308,187 Super User 2026 Season 2 on at

    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.

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

    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
    Joris dG Profile Picture
    17,782 on at

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

  • Suggested answer
    BrandonSA Profile Picture
    1,677 on at

    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

  • Peter Samir Profile Picture
    446 on at

    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
    nmaenpaa Profile Picture
    101,174 Moderator on at

    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
    446 on at

    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
    101,174 Moderator on at

    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
    446 on at

    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
    101,174 Moderator on at

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

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

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

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

Leaderboard > Finance

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans