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, ...
Suggested Answer

Call super in Extension class

(0) ShareShare
ReportReport
Posted on by 10

Hello,

    How can i call super() in extension method? 

I'm trying to create extension method for ValidateWrite method in "ProjForecastEmpl" table. I see that the ret = super(), in validate write method. So how can i call the super here in Extension class?

Thank you.

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    237,874 Most Valuable Professional on at

    You can't. super() is used with inheritance, not extensions.

    Assuming that you're talking abouut CoC (there is also a concept of extension methods meaning something else), use next validateWrite(); to call the actual ProjForecastEmpl.validateWrite() method. And because ProjForecastEmpl.validateWrite() calls super(), it'll be called in your case as well.

  • Suggested answer
    Anton Venter Profile Picture
    20,345 Super User 2025 Season 2 on at

    Hi DK,

    The super will be called automatically if you extend it correctly. Have a look at this article:

    Class extension - Method wrapping and Chain of Command

  • DK ram Profile Picture
    10 on at

    HI Martin/Anton,

      Thanks for your replies. Im using CoC, and when i have used the following code.

    public boolean validateWrite()
    {
    boolean ok;
    Amount amount;

    amount = this.orig().SalesPrice;

    ok = next validateWrite();

    if (this.SalesPrice == 0 && this.SalesPrice != amount)
    {
    warning(strFmt("@BSS:ProjForecastSalesPrice", this.SalesPrice, amount));
    }

    if (!this.BASRfcCategoryCode)
    {
    ok = checkFailed("RFC category is required. Please enter a value.");
    }

    return ok;
    }

    It's returning the warning only after closing the form. But user expects this warning to prevent form closing. And when I checked the ValidateWrite method, The ret is calling the super like below. Please suggest what to do.

    public boolean validateWrite()
    {
    ProjValCheckTrans projValCheckTrans = new ProjValCheckTrans();
    boolean ret;
    ForecastModel forecastModel;
    boolean isProjForecastReduced;

    isProjForecastReduced = this.isProjForecastReduced();

    ret = super();

    if (ret)
    {
    ret = this.checkModel() && ret;
    ret = this.checkActivity() && ret;
    ret = ProjTable::find(this.ProjId).status().validateWriteBudgetEmpl() && ret;
    ret = projValCheckTrans.validateMandatory(this) && ret;

    ret = ProjForecastPost::newPostForecastEmpl(this).runCheck() && ret;

    if (ret)
    {
    if (ProjTable::find(this.ProjId).StartDate > this.SchedFromDate)
    {
    ret= checkFailed("@SYS107206");
    }

  • WillWU Profile Picture
    22,361 on at

    Hi DK ram,

    Did you try to put the next validateWrite() method after your logic?

    ok= yourcheckgoes;
    
    if(ret)
    
    {
    
      ret = super();
    
    }
    
    else
    
    {
    
      info("......");
    
    }
    
    return ok;

    And please use insert code function to format your code:

    public boolean validateWrite()
    {
    boolean ok;
    Amount amount;
    
    amount = this.orig().SalesPrice;
    
    ok = next validateWrite();
    
    if (this.SalesPrice == 0 && this.SalesPrice != amount)
    {
    warning(strFmt("@BSS:ProjForecastSalesPrice", this.SalesPrice, amount));
    }
    
    if (!this.BASRfcCategoryCode)
    {
    ok = checkFailed("RFC category is required. Please enter a value.");
    }
    
    return ok;
    }
    
    
    
    public boolean validateWrite()
    {
    ProjValCheckTrans projValCheckTrans = new ProjValCheckTrans();
    boolean ret;
    ForecastModel forecastModel;
    boolean isProjForecastReduced;
    
    isProjForecastReduced = this.isProjForecastReduced();
    
    ret = super();
    
    if (ret)
    {
    ret = this.checkModel() && ret;
    ret = this.checkActivity() && ret;
    ret = ProjTable::find(this.ProjId).status().validateWriteBudgetEmpl() && ret;
    ret = projValCheckTrans.validateMandatory(this) && ret;
    
    ret = ProjForecastPost::newPostForecastEmpl(this).runCheck() && ret;
    
    if (ret)
    {
    if (ProjTable::find(this.ProjId).StartDate > this.SchedFromDate)
    {
    ret= checkFailed("@SYS107206");
    }

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

    Please always use Insert > Insert Code to paste source code. If you paste code without indentation, as you did, it's very difficult to read.

    Isn't this much better?

    public boolean validateWrite()
    {
    	boolean ok = next validateWrite();
    	Amount amount = this.orig().SalesPrice;
    
    	if (this.SalesPrice == 0 && this.SalesPrice != amount)
    	{
    		warning(strFmt("@BSS:ProjForecastSalesPrice", this.SalesPrice, amount));
    	}
    
    	if (!this.BASRfcCategoryCode)
    	{
    		ok = checkFailed("RFC category is required. Please enter a value.");
    	}
    
    	return ok;
    }

    Which warning are you talking about? Do you realize that your first "if" block doesn't set the return value to false?

    Please check it in the debugger if you don't believe us that next validateWrite() calls the method you're extending, including super().

  • DK ram Profile Picture
    10 on at

      
            if (!this.BASRfcCategoryCode)
            {
                ok = checkFailed("RFC category is required. Please enter a value.");
            }      
    

    Hi Martin,

        I talking about second if block. I even debugged the code, And i see that boolean is returning False, but the form is still closing and i get the warning message after the form closed.

  • Anton Venter Profile Picture
    20,345 Super User 2025 Season 2 on at

    I agree with Martin, your first if statement only shows a warning and does not set the return value to false like the second if statement. This might not be enough to stop the form from closing though, you will have to check that.

  • Anton Venter Profile Picture
    20,345 Super User 2025 Season 2 on at

    Check the form to see what needs to be done. I usually use/override the canClose form method to stop the form from closing.

  • nmaenpaa Profile Picture
    101,160 Moderator on at

    If your form closes even if validateWrite returns false, it has nothing to do with extensions or Chain of Command in validateWrite method.

  • Vishals786 Profile Picture
    on at

    Hi ,

    Whenever you are calling the methods of a standard object - table or a class in an extension. You have to use next keyword.

    Your code should look something like below : -

           [Extensionof(tablestr(ProjForecastEmpl))]

           final class ProjForecastEmpl_Extension

           {

              public boolean validateWrite(boolean ret)

              {

                   ret = next validateWrite(ret);

                   // Your condition goes here

               }

           }

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

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 289 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans