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.

  • Vishals786 Profile Picture
    on at
    RE: Call super in Extension class

    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

               }

           }

  • nmaenpaa Profile Picture
    101,156 Moderator on at
    RE: Call super in Extension class

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

  • Anton Venter Profile Picture
    19,545 Super User 2025 Season 1 on at
    RE: Call super in Extension class

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

  • Anton Venter Profile Picture
    19,545 Super User 2025 Season 1 on at
    RE: Call super in Extension class

    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.

  • DK ram Profile Picture
    10 on at
    RE: Call super in Extension class

      
            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.

  • Martin Dráb Profile Picture
    231,923 Most Valuable Professional on at
    RE: Call super in Extension class

    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().

  • WillWU Profile Picture
    22,352 on at
    RE: Call super in Extension class

    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");
    }

  • DK ram Profile Picture
    10 on at
    RE: Call super in Extension class

    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");
    }

  • Suggested answer
    Anton Venter Profile Picture
    19,545 Super User 2025 Season 1 on at
    RE: Call super in Extension class

    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

  • Suggested answer
    Martin Dráb Profile Picture
    231,923 Most Valuable Professional on at
    RE: Call super in Extension class

    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.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,207 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,923 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans