web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / ELandAX blog / The order of parameters in ...

The order of parameters in method override (registerOverrideMethod)

Evaldas Profile Picture Evaldas 1,800
Hello AX World,

Recently I have discovered something unexpected about registerOverrideMethod

If you are familiar with the following run time error messages, then probably you know what I will be talking about.

Attempt by method [x] to access type [y] failed.
Error executing code: [x] object does not have method [y].

Unable to cast object of type [x] to type [y].



Those are the 3 messages I've got trying to override forms data source method leaveRecord and tab control method tabChange.

The 1st error message was caused by the following override method. This is what you would expect to have. The original method has one parameter with default value, therefore, adding the second parameter FormDataSource requires a default value too.

public boolean leaveRecord(boolean _forceUpdate = false, FormDataSource _formDataSource = null)
{
return true;
}

The 2nd error message was called by the same override method without default values. I thought, maybe it's the cause. It turned out, it's not.

public boolean leaveRecord(boolean _forceUpdate, FormDataSource _formDataSource)
{
return true;
}

Before explaining the 3rd error message, which is similar to the 1st one, I have to explain how I found the solution. I did other attempts trying to figure out what's wrong. They all, but the last one, resulted in the same error messages.
My last attempt was to switch the order of the parameters. FormDataSource was placed 1st and the original parameter followed it. It worked!


public boolean leaveRecord(FormDataSource _formDataSource, boolean _forceUpdate = false)
{
return true;
}

I thought, why then tabChange override, which I discussed in the previous blog post, works perfectly and this one does not? I tried to change the order of its parameters. Then I've got the 3rd error.

protected boolean tabChange(FormTabControl _tabControl, int _fromTab)
{
return true;
}

The override was registered in a form extension class like shown in the following code example:

smmBusRelTable_ds.registerOverrideMethod(methodStr(FormDataSource, leaveRecord), 
methodStr(smmBusRelTableForm_Extension, leaveRecord),
this);

I was thinking why it could be like that and the only conclusion I have come up to was this.
Probably, method parameters, which originally have default values, must be placed in the end so we don't need to add a default to additional parameter like 
FormDataSource
I am not sure about that and if you have a better explanation leave it in the comments.

Be aware and take care!


This was originally posted here.

Comments

*This post is locked for comments