Announcements
Inside the LederTransAccount form, we want to add a control (for example, a CheckBox or a Radio Button) that allows users to hide or unhide certain grid fields. I.e., if the checkbox is unmarked, the form would appear as default (standard D365 fields), if the checkbox was marked, the form would refresh and exhibit the default fields + some other custom fields inside the grid (doing it this way since the field is a Display Method, therefore, users can't simply use the "Add Columns" option).
In order to this, I extended the form and created the custom field on the grid (Field123) and the checkbox (CheckBox123), with the caption "Show Form with Field123".
My issue now is what I actually need to do to connect both the checkbox and the form refresh process and what logic should I write in the backstage (even more given the fact that this an extension, blocking me from adding custom methods directly into the form controls).
Hi joaoasilva11,
As Martin explained previously, this class will be an extension of this form control only. You don't have the option of having an extension class for the form in which you will be able to write code for another control. If you are going ahead with CoC, you need to create individual classes for individual controls.
The alternated approach, as Martin also mentioned before, is to create a class for event handlers and place all the event handlers for the form, data sources, controls etc. in this class.
Poor explanation by me, you're right. What I meant is, this class is specific to this control only. Is it possible to create an extension class of the form and inside that class have multiple "form controls"? I.e., so far I have this specific code for this specific control, but in the future, if we need to create another code logic for another control, I would like them to be inside the same general class and not in multiple classes.
You're right - this is an extension of FCMShowReversedField in LedgerTransAccount form - it can't be used for anything else.
But I'm not sure what you mean by a general/broad class.
If you want to override controls of the form, for example, create another class as an extension of the form: [ExtensionOf(formStr(LedgerTransAccount))].
If you mean that you want to use the same logic for several fields, one option is using several control extensions and calling the same method from each of them.
Another approach is using an event handler instead of CoC, because the handler method can handle events coming from different controls.
Makes sense. I think the mentioned code works. Tested it inside my environment and everything worked as expected.
My main question now is how to change my initial class. Since I have this portion of code before my class declaration
[ExtensionOf(formControlStr(LedgerTransAccount, FCMShowReversedField))]
I assume that every method I write inside this function will always be "attached" to FCMShowReversedField. Is there a way to make the overall class a "general" / broad one and only apply this control portion to that specific modified() method?
Modified is a boolean method. So, you need to return a boolean value for this . As for the form control, you can declare a variable of type FormControl and set the visible property on that. Please try the code below and see if that works for you.
public boolean modified() { boolean ret = next modified(); FormControl reversedCtrl = element.FCMReversed; reversedCtrl.visible(this.checked()); return ret; }
Yes, of course.
Could you please share your final code so that we can see which line is throwing the error?
Oh alright, got it. Gunjan Bhattachayya used this method in his solution. It makes sense, since I'm already extending the object. Understood!
Any idea why it's throwing a "Invalid token (" on the last code line?
Because you're doing it wrong.
'this' is the checkbox control and you want to call its checked() method, which is done this way: this.checked().
Your code is string to access FCMShowRversedField of the checkbox control, and nothing like that exists.
The element variable appears to have fixed the FCMReversed field, but 'this' didn't seem to work:
André Arnaud de Cal...
294,060
Super User 2025 Season 1
Martin Dráb
232,858
Most Valuable Professional
nmaenpaa
101,158
Moderator