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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Event Handler on Field Group

(0) ShareShare
ReportReport
Posted on by 313

I'm trying to run some lookup code on a form control but this control is part of a field group.  I was able to run this same code on other controls that are not part of the group just fine but when I copy the event handler, it gives me an error saying the control is not found.

Here is my control

pastedimage1681219270862v1.png

I copy the event handler for OnLookup and paste it in my class but then I get this

pastedimage1681219318863v2.png

What do I need to do different in order to get this code to compile?

I have the same question (0)
  • Suggested answer
    Mohit Rampal Profile Picture
    12,565 Moderator on at

    Hi Andrew, How about using form datasource field lookup instead of form design control

    https://wp.me/p7uQZu-nv

  • Suggested answer
    huijij Profile Picture
    19,811 on at

    Hi Andrew,

    For the error message, most likely you have placed your event handler code in a different package than your field group.

    In this case you need to add package reference, otherwise your event handler package can't see the objects of the other package.

  • Andrew Huisman Profile Picture
    313 on at

    That form control and field group is in an extension of that table that I created.  Does that change how I should be calling it?

  • Andrew Huisman Profile Picture
    313 on at

    Hi Mohit, I looked at that link but I'm not sure how to do that.

  • Mohit Rampal Profile Picture
    12,565 Moderator on at

    Hi Andrew, I am able to access field in field group on form control in onlookup event handler. Please share your code, it might be issue there.

  • Andrew Huisman Profile Picture
    313 on at

    Here is my code.  As you can see, I already have the lookup for another instance of the Problem Sub Type on a different tab.  The thing is, the tab that I'm trying to get it to work on, the formcontrol is inside a field group like I mentioned.  As soon as I add the code at the bottom, it give me the error

    public class InventNonConformanceTable_Form_Handlers
    {
        /// 
        ///
        /// 
        /// 
        /// 
        [FormControlEventHandler(formControlStr(InventNonConformanceTable, InventNonConformanceTable_TCI_InventRootSubTypeId), FormControlEventType::Lookup)]
        public static void InventNonConformanceTable_TCI_InventRootSubTypeId_OnLookup(FormControl sender, FormControlEventArgs e)
        {
            //Specify the name of the table the lookup should show data from.
            SysTableLookup          sysTableLookup = SysTableLookup::newParameters(tableNum(TCI_InventRootSubType), sender);
    
            FormRun         formRun = sender.formRun();
            FormDataSource  dataSoruce_ds = sender.formRun().dataSource();
            //To get the buffer use below code.
            //TableName       tableBuffer = dataSoruce_ds.cursor();
            //To get control value refer to beloe code
            FormControl     controlName = formRun.design().controlName("InventNonConformanceTable_TCI_InventRootTypeId");
    
    
            //Cancel super
            FormControlCancelableSuperEventArgs     event = e as FormControlCancelableSuperEventArgs;
            event.CancelSuperCall();
    
            //Create a new query
            Query                   query = new Query();
            QueryBuildDataSource    queryBuildDataSource;
            QueryBuildRange         queryBuildRange;
    
            //Specify the name of the table the lookup should show data from.
            queryBuildDataSource = query.addDataSource(tableNum(TCI_InventRootSubType));
            queryBuildRange = queryBuildDataSource.addRange(fieldNum(TCI_InventRootSubType,TCI_InventRootTypeId));
            queryBuildRange.value(queryValue(controlName.valueStr()));
    
            //Specify which fields should be shown  in the lookup form.
            //  field returned is the first field referenced
            sysTableLookup.addLookupfield(fieldNum(TCI_InventRootSubType, TCI_InventRootSubTypeId));
            sysTableLookup.addLookupfield(fieldNum(TCI_InventRootSubType, Description));
    
            sysTableLookup.parmQuery(query);
            sysTableLookup.performFormLookup();
        }
    
        /// 
        ///
        /// 
        /// 
        /// 
        [FormControlEventHandler(formControlStr(InventNonConformanceTable, InventNonConformanceTable_TCI_InventProblemSubTypeId), FormControlEventType::Lookup)]
        public static void InventNonConformanceTable_TCI_InventProblemSubTypeId_OnLookup(FormControl sender, FormControlEventArgs e)
        {
            //Specify the name of the table the lookup should show data from.
            SysTableLookup          sysTableLookup = SysTableLookup::newParameters(tableNum(TCI_InventProblemSubType), sender);
    
            FormRun         formRun = sender.formRun();
            FormDataSource  dataSoruce_ds = sender.formRun().dataSource();
            //To get the buffer use below code.
            //TableName       tableBuffer = dataSoruce_ds.cursor();
            //To get control value refer to beloe code
            FormControl     controlName = formRun.design().controlName("InventNonConformanceTable_InventTestProblemTypeId");
    
            //Cancel super
            FormControlCancelableSuperEventArgs     event = e as FormControlCancelableSuperEventArgs;
            event.CancelSuperCall();
    
            //Create a new query
            Query                   query = new Query();
            QueryBuildDataSource    queryBuildDataSource;
            QueryBuildRange         queryBuildRange;
    
            //Specify the name of the table the lookup should show data from.
            queryBuildDataSource = query.addDataSource(tableNum(TCI_InventProblemSubType));
            queryBuildRange = queryBuildDataSource.addRange(fieldNum(TCI_InventProblemSubType,ProblemTypeId));
            queryBuildRange.value(queryValue(controlName.valueStr()));
    
            //Specify which fields should be shown  in the lookup form.
            //  field returned is the first field referenced
            sysTableLookup.addLookupfield(fieldNum(TCI_InventProblemSubType, ProblemSubTypeId));
            sysTableLookup.addLookupfield(fieldNum(TCI_InventProblemSubType, Description));
    
            sysTableLookup.parmQuery(query);
            sysTableLookup.performFormLookup();
        }
    
        /// 
        ///
        /// 
        /// 
        /// 
        [FormControlEventHandler(formControlStr(InventNonConformanceTable, ProblemInformation_TCI_InventProblemSubTypeId), FormControlEventType::Lookup)]
        public static void ProblemInformation_TCI_InventProblemSubTypeId_OnLookup(FormControl sender, FormControlEventArgs e)
        {
        }
        
    
    
    }

    pastedimage1681479847469v1.png

  • Andrew Huisman Profile Picture
    313 on at

    Hi Mohit, have you had a chance to look at my code?

  • Suggested answer
    Mohit Rampal Profile Picture
    12,565 Moderator on at

    Hi Andrew, I just replicated your issue by trying to use onLookup event of custom field in a field group. I have noticed that this issue occurs only for custom fields. You can check using OnLookup for 'Quarantine_QuarantineZoneId' control in InventNonConformanceTable form and compiler will not throw error, even though this field is in a field group.

    I believe this is limitation on new fields and to fix it you have move the field out of the field group.

    There is a thread on same issue, Check this out.

    community.dynamics.com/.../form-control-is-not-found-in-form

  • Suggested answer
    Andrew Huisman Profile Picture
    313 on at

    Okay, I will remove it from the field group.  Thanks for your help!

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 660 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 291 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans