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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Event Handler in Form Lookup doesnt work

(0) ShareShare
ReportReport
Posted on by 157

Hello to everyone

I try to modify the existing lookup method in a form control.

But the debuger never enter the event handler that I create.

The structure of the form and the lookup method is as you can see in the image below:

formLookup.PNG

the existing lookup method is like below

[Control("ReferenceGroup")]
class LoanObject
{
       public void lookup()
       {
               SysReferenceTableLookup lookup = SysReferenceTableLookup::newParameters(tableNum(EntAssetObjectTable), this);

              Query query = new Query();
              QueryBuildDataSource qbdsObjectTable = query.addDataSource(tableNum(EntAssetObjectTable));

             qbdsObjectTable.addRange(fieldNum(EntAssetObjectTable, ObjectType)).value(SysQuery::value(objectTable.ObjectType));
             qbdsObjectTable.addRange(fieldNum(EntAssetObjectTable,                              ObjectLifecycleState)).value(SysQuery::value(objectTable.ObjectType().ObjectLifecycleModel().InStorageLifecycleState));

            lookup.parmQuery(query);
            lookup.addLookupfield(fieldNum(EntAssetObjectTable, ObjectID));
            lookup.addLookupfield(fieldNum(EntAssetObjectTable, Name));

            lookup.performFormLookup();
        }

}

and the new class that I create is like below

class EntAssetObjectLoanSend_Form_MyModel_handlers
{

          [FormControlEventHandler(formControlStr(EntAssetObjectLoanSend, LoanObject), FormControlEventType::Lookup)]
          public static void LoanObject_OnLookup(FormControl _sender, FormControlEventArgs _e)
          {
                 FormRun                        form                      = _sender.formRun();
                 FormDataSource           objectTable_ds     = form.dataSource(formDataSourceStr(EntAssetObjectLoanSend, ObjectTable)) as FormDataSource;
                 EntAssetObjectTable     objectTable           = objectTable_ds.cursor();

                 info(strFmt("%1",objectTable.MyModel_MyField));

                 FormControlCancelableSuperEventArgs ce = _e as FormControlCancelableSuperEventArgs;
                 ce.CancelSuperCall();
          }

}

Does anybody understand why this doesn't work and my method never run?

I have the same question (0)
  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi SGbron,

    We have encountered this issue before. The only workaround we could come up with was to set the original control to Visible = false and duplicate the control in the form extension. You can then use the lookup event in this new control to create the custom lookup.

  • SGbron Profile Picture
    157 on at

    Hi Gunjan

    Thank you for your reply.

    Sadly I cannot do this because this control also used while creating the records.

  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi SGbron,

    Could you please share which form you are working with? If it is a standard form, we can take a look and try to look for workaround.

  • Verified answer
    SGbron Profile Picture
    157 on at

    finally I found a way to do it...

    By creating a class that extends the form and by override the original lookup method like this

    [ExtensionOf(formStr(EntAssetObjectLoanSend))]

    final class EntAssetObjectLoanSend_Form_MyModel_Extension

    {

       void init()

       {

           next init();

           LoanObject.registerOverrideMethod(methodStr(FormDataObject, lookup),

           formMethodStr(EntAssetObjectLoanSend, myLoanObjectLookup));

       }

       public void myLoanObjectLookup(FormControl _callingControl)

       {

           SysReferenceTableLookup sysTableLookup          =

           SysReferenceTableLookup::newParameters(tableNum(EntAssetObjectTable), _callingControl);

           Query                   q                       = new Query();

           QueryBuildDataSource    qbdsObjectTable         =

           q.addDataSource(tableNum(EntAssetObjectTable));

           qbdsObjectTable.addRange(fieldNum(EntAssetObjectTable,

           ObjectType)).value(SysQuery::value(objectTable.ObjectType));

           qbdsObjectTable.addRange(fieldNum(EntAssetObjectTable,

    ObjectLifecycleState)).value(SysQuery::value(objectTable.ObjectType().ObjectLifecycleModel().InStor

    ageLifecycleState));

           qbdsObjectTable.addRange(fieldNum(EntAssetObjectTable,

           MyModelMyField)).value(SysQuery::value(NoYes::Yes));

           sysTableLookup.parmQuery(q);

           sysTableLookup.addLookupfield(fieldNum(EntAssetObjectTable, ObjectID));

           sysTableLookup.addLookupfield(fieldNum(EntAssetObjectTable, Name));

           sysTableLookup.parmQuery(q);

           sysTableLookup.performFormLookup();

       }

    }

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 620

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 521 Super User 2026 Season 1

#3
CP04-islander Profile Picture

CP04-islander 430

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans