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 / Unable to override tab...
Finance forum

Unable to override table methods

(0) ShareShare
ReportReport
Posted on by 20

Folks,

UPDATE: I did end up having to create an extensibility request for this and it is supposed to be in 8.1.3.  Thanks so much for everyone's responses!

I've seen the post by Ievgen on how to override a form data source field method:

https://ievgensaxblog.wordpress.com/2016/05/01/ax-7-how-to-override-form-data-source-field-methods-without-overlaying/

I wanted to apply the same approach to override a table method, say validateWrite() on the TSTimesheetFavorites table, but wasn't certain how to go about doing that.

7183.2018_2D00_03_2D00_08_5F00_16_2D00_15_2D00_28.png

Here are the methods available on that table, but they all could be called multiple times, and would not be good candidates for calling registerOverrideMethod(), as I believe that will cause an error, as per this blog post:

https://shyamkannadasan.blogspot.ca/2016/08/registeroverridemethod-was-called-twice.html

Let's say that that issue was solved, the next issue is the syntax used by Ievgen doesn't seem to apply to tables: 

    [DataEventHandler(tableStr(TSTimesheetFavorites), DataEventType::ValidatingWrite)]
    public static void TSTimesheetFavorites_onValidatingWrite(Common sender, DataEventArgs e)
    {

        var overrides = TSTimesheetFavoritesEventOverrides::construct();

   sender.registerOverrideMethod(tableMethodStr(TSTimesheetFavorites,validateWrite),methodStr(TCK_TSTimesheetFavoritesEventOverrides, validateWrite),overrides);
    }

This will build, but during runtime, it will error out when it hits this method:

Error executing code: TSTimesheetFavorites table does not have method 'registerOverrideMethod'

Any ideas on how to override built-in table methods using the extension approach?

Thanks!

I have the same question (0)
  • Princeton Lau Profile Picture
    20 on at

    Hi Sukrut!

    Ah, the problem is, I do not want the standard code in validateWrite() to fire... I can definitely hook up to the onValidateWrite or onValidatedWrite, but this will only ADD logic on top of the standard code, which is not what I would like.

    Any other ideas?

    Thanks!

  • Martin Dráb Profile Picture
    238,743 Most Valuable Professional on at

    This approach isn't applicable to tables. And disabling standard checks in validateWrite() doesn't sounds like an extension.

  • Suggested answer
    Mea_ Profile Picture
    60,286 on at

    You cannot override it, so you have to use either events or CoC to add stuff. Sometimes you can prevent standard code execution paying with parameters in pre handler but I would not recommend to do this as well because it can cause issues if source code would be changed by update or hot fix.

  • Princeton Lau Profile Picture
    20 on at

    Hi Martin!

    Thanks for all your posts over the years!

    We need to disable the standard checks in validateWrite() as we have extended the table to include more fields, beyond the ones Microsoft is using:

                    if (TSTimesheetFavorites::exist(this.TableGroupAll, this.Resource, this.ProjId, this.CategoryId, this.ActivityNumber))
                    {
                        result = checkFailed("@SYS343246");
                    }
    

    Ideally, we'd write our own validation, which includes the additional fields, to ensure they are unique.

    If we cannot use this approach, what would you suggest as an alternative?

    Thanks!

  • Princeton Lau Profile Picture
    20 on at

    Hi Ievgen!

    Thanks so much for your original post!

    As I mentioned to Martin, we are trying to prevent the standard validation from firing, seems like neither events or CoC will work, as they both will still call the standard validation...

    For the pre handler, it doesn't seem like there is a lot that we have to work with:

        [PreHandlerFor(tableStr(TSTimesheetFavorites), tableMethodStr(TSTimesheetFavorites, validateWrite))]
        public static void TSTimesheetFavorites_Pre_validateWrite(XppPrePostArgs args)
        {
        }
    

    I know that you wouldn't recommend this approach, but if you were to do it, how would you go about it?

    Thanks!

  • Mea_ Profile Picture
    60,286 on at

    There is always bad and dirty way. Like in pre of validate write set global flag, then in post of exist check this flag and return true instead of false.

    But again doing this you creating lots of issue that would be hard to debug and fix, so try to avoid dodgy solutions like this.

  • Martin Dráb Profile Picture
    238,743 Most Valuable Professional on at

    If you need to extend Microsoft code that isn't extensible, please create an extensibility request.

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

    You can't change the unique index of standard tables with extensions, so please check first if your changes to the table should be redesigned. Then you might notice that you don't need to change this validation that you are referring to.

    If you want to have multiple records for one TableGroupAll, Resource, ProjId, CategoryId and ActivityNumber combination you should consider creating a new table for this purpose, and linking all such records of your table to the one unique record of the standard table. Or copying the standard table and then modifying it to suit your needs. Really depends on the case.

  • Princeton Lau Profile Picture
    20 on at

    Hi Nikolaos!

    In the case of the TSTimesheetFavorites table, it does not have a unique index, instead Microsoft has put in a validation in the validateWrite() method, which is what we are trying to change.

    2703.2018_2D00_03_2D00_14_5F00_10_2D00_03_2D00_21.png2703.2018_2D00_03_2D00_14_5F00_10_2D00_03_2D00_21.png

    We could create a new table, however, there would be a fair bit of effort to hook it up to the existing infrastructure... plus it would be an extra thing to worry about when Microsoft deploys updates.

    Martin,

    There is a webinar about this topic tomorrow, if I'm not able to get it resolved then, I will put in a request to Microsoft.

    Thanks again for all your responses!

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