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, ...
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

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 611 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans