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 :
Finance | Project Operations, Human Resources, ...
Answered

Extension methods for FormControl and Form

(0) ShareShare
ReportReport
Posted on by 1,845

Hi,

I created a form extension and added a new button then I created the following class to be able to override clicked method

[ExtensionOf(formControlStr(CaseDetail,AAbtnNewCase))]
final class CaseDetailAA_Extension
{

public void clicked()
{
   //logic
}

name of class is CaseDetailAA_Extension

now if I want to add a new method for the form caseDetail which is AACreateRecord -- similar to the standard createRecord method in this class and call it inside the clicked method, shall I add this new method in this class I created?

[ExtensionOf(formControlStr(CaseDetail,AAbtnNewCase))]
final class CaseDetailAA_Extension
{

public void clicked()
{
   this.aaCreateRecord();
}

public void aaCreateRecord()

{

  //logic
}



OR

shall I create a new class with [ExtensionOf(formlStr(CaseDetail))] and add aaCreateRecord() in it? if that's the case then this class needs to be CaseDetailAA_Extension. Then what should I rename the extension class for the formControl? what's the best practice? would this work  CaseDetailFormControlAA_Extension?

I have the same question (0)
  • Martin Dráb Profile Picture
    235,961 Most Valuable Professional on at
    RE: Extension methods for FormControl and Form

    You misunderstood my reply. The topic of type is covered by the previous sentence ("I find including the type in extensions names useful, because there often are multiple elements with the same name (e.g. table and form").

    The other senstence ("Also, I usually see company prefixes (AACaseDetail...) instead of suffixes.") is about a different topic, but related to your question about best practices.

  • .. Profile Picture
    1,845 on at
    RE: Extension methods for FormControl and Form

    Hi Martin,

    no thank you but a comment on your last point  "Also, I usually see company prefixes (AACaseDetail...) instead of suffixes."

    The prefix still won't help if the there table and form are named the same. so i think a suffix with the work Form or table  might help more.

    unless you were talking about sth else that i can name the class AASth_Extension or SthAA_Extension

  • Martin Dráb Profile Picture
    235,961 Most Valuable Professional on at
    RE: Extension methods for FormControl and Form

    Is there anything more that you want to know about the topic of this thread (whether you should add the method to the form control extension or a form extension)? If not, please verify the answer.

  • .. Profile Picture
    1,845 on at
    RE: Extension methods for FormControl and Form

    Hi Martin,

    I created the aaCreateRecord in the form extension, but I can't call it from the form control extension

    community.dynamics.com/.../how-to-call-a-method-in-a-form-extension-class-from-a-form-control-extension-class

  • Verified answer
    Martin Dráb Profile Picture
    235,961 Most Valuable Professional on at
    RE: Extension methods for FormControl and Form

    Where the method should be depends on what it does and how it's supposed to be used.

    As far as I know, there are no best practices about how the names should be formed. I find including the type in extensions names useful, because there often are multiple elements with the same name (e.g. table and form). Also, I usually see company prefixes (AACaseDetail...) instead of suffixes.

  • .. Profile Picture
    1,845 on at
    RE: Extension methods for FormControl and Form

    Hi Martin,

    but because the standard method createRecord is for the form, so I thought I should do it on form level as well.

    So what you are saying if I'm only going to call it in the form control method then I can keep the method in the control class, correct?

    but let's say I want to create two classes, is this what should I call each class as a best practice?
    CaseDetailAA_Extension  -- for the form  , or shall I call it CaseDetailFormAA_Extension?
    CaseDetailFormControlAA_Extension   
    -- for the control

  • Martin Dráb Profile Picture
    235,961 Most Valuable Professional on at
    RE: Extension methods for FormControl and Form

    You have an erxtension of a form control. If you add a method there, it'll be a method of the form control, not of the form that contains the control. You should decide what you actually want.

    If having it in AAbtnNewCase class is sufficient, just do it - then you don't need an extra class with the form extension.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Sohaib Cheema Profile Picture

Sohaib Cheema 789 User Group Leader

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 607 Super User 2025 Season 2

#3
Martin Dráb Profile Picture

Martin Dráb 497 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans