Reputation: 47
I want to program with the Method super() in Dynamics AX2012.
I have build a class ("A") and some methods in it. I build another class("B") whhich extends from the class before.
My class "A" has some Methods.
Now in Class "B" I want to override a Method. I will do so.
I will override the Method getTable().
protected SYCCarBrandTable getTable()
{
SYCCarBrandTable ret;
ret = super();
{
select brandid,branddescription from ret
where ret.brandid == "Bentley";
}
return ret;
}
Now my Question is...
I have understood that with super() this new method did take everything with it, from the method which it Extended from in the motherclass "A".
But how can I add more Things to the method, so that it gives me the Things from the method before and the Things I have added in the overriden method ?
Upvotes: 1
Views: 2053
Reputation: 265
If you want to add additional critria to a select you should use query object and design your select. Than you should create a new method on your base class called something like modifieQuery() or setQueryRange(). In this method you add range to your query as you want for base class. When you override this method in your class "B" you call super and than add additional ranges or simply override method without super() and just set ranges as needed. In your getTable method on base class you call modifieQuery() and execute it.
Upvotes: 0
Reputation: 433
Looking at the implementation of getTable(), looks like you may want to select some SYCCarBrandTable record using the values of another SYCCarBrandTable returned by super() as criteria + other newly added criteria.
I am not sure why you would like to do such a thing, but if you perform the select statement upon the same table variable, you are actually really overriding all behavior, not adding anything.
If I got it right, you may want to use another SYCCarBrandTable:
protected SYCCarBrandTable getTable()
{
SYCCarBrandTable superCar;
SYCCarBrandTable ret;
superCar = super();
select brandid,branddescription from ret
where ret.CriteriaA = superCar.CriteriaA
&& ret.brandid == "Bentley";
return ret;
}
Then again, I am not sure why such a thing would be useful, but this is one sample way of aggregating functionality instead of fully overriding it.
Upvotes: 0