Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

Event Handler on Field Group

(0) ShareShare
ReportReport
Posted on by 284

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?

  • Suggested answer
    Andrew Huisman Profile Picture
    Andrew Huisman 284 on at
    RE: Event Handler on Field Group

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

  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: Event Handler on Field Group

    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

  • Andrew Huisman Profile Picture
    Andrew Huisman 284 on at
    RE: Event Handler on Field Group

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

  • Andrew Huisman Profile Picture
    Andrew Huisman 284 on at
    RE: Event Handler on Field Group

    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

  • Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: Event Handler on Field Group

    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
    Andrew Huisman 284 on at
    RE: Event Handler on Field Group

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

  • Andrew Huisman Profile Picture
    Andrew Huisman 284 on at
    RE: Event Handler on Field Group

    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?

  • Suggested answer
    huijij Profile Picture
    huijij 19,811 on at
    RE: Event Handler on Field Group

    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.

  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: Event Handler on Field Group

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

    https://wp.me/p7uQZu-nv

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,979 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,848 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans