How to extend a form's data source field added in a form extension?
Views (3723)
Hello AX World,
Let's say you have a form extension where you added a new data source.
You need to extend a field of the new data source.
The first thought that comes to my mind is to create a class extension of this field.
After compiling, I get the following error:
Abnormal termination with unhandled exception. Exception key: ... System.NullReferenceException: Object reference not set to an instance of an object.
Without further explanation, I will tell you that this is not possible. At least in PU24.
You can extend any data source field but not the one added in a form extension.
So what are the options?
Let's say you have a form extension where you added a new data source.
You need to extend a field of the new data source.
The first thought that comes to my mind is to create a class extension of this field.
[ExtensionOf(formDataFieldStr(Form, NewDataSource, DataField))]
final class FormDataField_Extension
{
...
}
After compiling, I get the following error:
Abnormal termination with unhandled exception. Exception key: ... System.NullReferenceException: Object reference not set to an instance of an object.
Without further explanation, I will tell you that this is not possible. At least in PU24.
You can extend any data source field but not the one added in a form extension.
So what are the options?
- Hookup to framework events if you need to extend modified or validate.
- Extend a form's control instead.
- Register method override with registerOverrideMethod. This one is useful in case you need to override lookupReference or resolveReference methods.
Important note: When overriding lookupReference and resolveReference overriden method signature should be the following.
Note that there is no FormReferenceObject or FormDataObject parameter. Example bellow shows you how to get a table record.
public Common lookupReference(FormReferenceGroupControl_control)
{
FormObjectSet formObjectSet = _control.formRun().dataSource(tableStr(Table));
Table table = formObjectSet.cursor();
return Table::lookupReference(table.FilterField, _control);
}
Be aware and take care!
This was originally posted here.
*This post is locked for comments