Tuesday, January 25, 2011

Super() ... When design gets in the way : (

The following is the definition from this web site http://msdn.microsoft.com/en-us/library/dd261515.aspx

The super keyword is used in a derived class to access the same method on its base class.
void method2()
// Call method2 method
// on the base class.
I was having a problem when trying to write a new Quote into SalesQuotationTable this morning. For some reason every time I wanted to create a new quote (by clicking OK), a warning message would come up saying "The field Business Relation has to be filled".

Ok, no problem, the above told me that probably the last developer set the field to be mandatory or there should have been something in the code that was checking for this field to be filled.

The strange thing was that the field wasn't mandatory and depending from where the quote was coming, the field would not be needed. For example, if the Business Relation account was converted to a Customer, the business relation does not show in the SalesCreationQuotation Form. Instead we show the Customer Account and viceversa.

This is the code that decides that:

prospect          = (accountType.selection() == smmQuotationAccountType::BusRelAccount) ? true : false;
    if (prospect)
Now, with this information I started suspecting about my classes calling base classes methods that I was not aware of, and I took a close look to the Super calls.

So from the ValidateWrite() method in the SalesCreationQuote Form, the Super() would call the ValidateWrite() method in the SalesQuotationTable. Now, I discovered that the ValidateWrite() method in the SalesQuotationTable Super() call was always directed to a class to show an info log.

After reading this blog http://daxguy.blogspot.com/2006/12/super.html I decided to suppress the Super() call from the ValidateWrite() method in the SalesQuotationTable and I was able to write to the SalesQuotationTable with no problem.

I tested it with records being called from the Business Relation Form, or straight from the SalesQuotationDetails and choosing a new record manually.

: )

No comments:

Post a Comment

Thank you for your thoughts. Your comment will appear in my blog shortly after review.

Have a great day!