Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / Call form extension me...
Finance forum
Suggested answer

Call form extension method on datafield event handler

Posted on by 6
Hello everybody, 
 
I have added FieldA on ProjTable table and eventually in the form. 
I need to run some logic when the field is modified on the form.
So, I have created MethodA on ProjTable_Form_Extension class and I am trying to call it from the data field event handler.
Below the code:
 
  [FormDataFieldEventHandler(formDataFieldStr(ProjTable, ProjTable, FieldA), FormDataFieldEventType::Modified)]
    public static void FieldA_OnModified(FormDataObject sender, FormDataFieldEventArgs e)
    {
        FormDataSource  projTable_ds   = sender.datasource() as FormDataSource;
        FormRun              formRun         = sender.datasource().formRun() as FormRun;
        ProjTable             projTable         = projTable_ds.cursor();
       
            formRun.methodA();
        }
    }
 
[ExtensionOf(formStr(ProjTable))]
final class ProjTable_Form_Extension
{
    public void methodA()
    {
          //logic here
    }
}
 
When I modify the field on the form, I get the below error:  FormRun object does not have method 'methodA'.
 
Can anybody help me, please? 
Thanks in advance!
  • Waed Ayyad Profile Picture
    Waed Ayyad 3,758 on at
    Call form extension method on datafield event handler
    Hi,

    Is your issue resolved?  If yes, mark the answers that helped you as verified.

    Thanks
    Waed Ayyad
  • Suggested answer
    Waed Ayyad Profile Picture
    Waed Ayyad 3,758 on at
    Call form extension method on datafield event handler
    Hi,

    Is your issue resolved?  If yes, mark the answers that helped you as verified.

    Thanks
    Waed Ayyad
  • Suggested answer
    Waed Ayyad Profile Picture
    Waed Ayyad 3,758 on at
    Call form extension method on datafield event handler
    Hi,
     
    Use the FormDataSourceField COC and add your method there.
     
    [ExtensionOf(formDataFieldStr(ProjTable, ProjTable, FieldA))]
    final class XXXProjTable_ProjTableFieldA_Extension
    {
        public void modified()
        {
            FormDataObject formDataObject = any2Object(this) as FormDataObject;
            FormDataSource formDataSource = formDataObject.datasource();
    
            next modified();
    ​​​​​​​ this.MethodA(); } public void methodA() { //logic here } }
    Thanks,
    Waed Ayyad
    If this helped, please mark it as "Verified" for others facing the same issue
  • Martin Dráb Profile Picture
    Martin Dráb 225,549 Super User on at
    Call form extension method on datafield event handler
    A better approach will be using a CoC extension of the data source and referring the the form by element variable.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,914 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,549 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans