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

Community site session details

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

OnLookUp Event Hanlder doesn't work.

(0) ShareShare
ReportReport
Posted on by 30

Hi!

I have a problem with using OnLookUp Event Handler.

Here is Standard Code that form name is LedgerJournalTransDaily and field name is editReasonCode.(editReasonCode is not a field, is a method)

    [Control("String")]
    class editReasonCode
    {
        /// 
        /// Displays a filtered version of the Reasons lookup form to the user based on the AccountType and the OffsetAccountType.
        /// 
        /// 
        /// This method will be called when the user open the reason code lookup form.
        /// 
        public void lookup()
        {
            LedgerJournalACType   offsetAccountType;
            LedgerJournalACType   accountType;
            boolean               useOffsetAccount;

            useOffsetAccount = ledgerJournalTrans.parmOffsetLedgerDimension() ? true : false;

            offsetAccountType = ledgerJournalTrans_ds.object(fieldNum(LedgerJournalTrans,OffsetAccountType)).getValue();
            accountType = ledgerJournalTrans_ds.object(fieldNum(LedgerJournalTrans,AccountType)).getValue();
            ReasonFormTable::reasonCodeLookup(this,offsetAccountType,accountType,true,useOffsetAccount);
        }

    }

And here is  "ReasonFormTable::reasonCodeLookup(this,offsetAccountType,accountType,true,useOffsetAccount);" Code.

public static void reasonCodeLookup(FormControl _formControl,
                                        LedgerJournalACType _offsetAccountType,
                                        LedgerJournalACType _accountMainType,
                                        boolean _useMainAccount = false,
                                        boolean _useOffsetAccount = false,
                                        LedgerJournalACType _accountType = LedgerJournalACType::Ledger,
                                        boolean _useAccountType = false)
    {
        Query                   query = new Query();
        QueryBuildDataSource    dsReasonTable;
        // Instantiate sysTableLookup object using table which will provide the visible fields
        SysTableLookup  sysTableLookup = SysTableLookup::newParameters(tableNum(ReasonTable), _formControl);
        
        // Create the query
        dsReasonTable = query.addDataSource(tableNum(ReasonTable));

        if(_useMainAccount)
        {
            ReasonFormTable::setAccountRange(_accountMainType, dsReasonTable);
        }

        if (_useOffsetAccount)
        {
            ReasonFormTable::setAccountRange(_offsetAccountType, dsReasonTable);
        }

        if (_useAccountType)
        {
            ReasonFormTable::setAccountRange(_accountType, dsReasonTable);
        }

        // Set the query to be used by the lookup form
        sysTableLookup.parmQuery(query);

        // Specify the fields to show in the form
        sysTableLookup.addLookupfield(fieldNum(ReasonTable, Reason));
        sysTableLookup.addLookupfield(fieldNum(ReasonTable, Description));

        // Perform the lookup
        sysTableLookup.performFormLookup();
    }

And, I want to add a condition in LookUp logic.

So, I copy the eventHandler according to the editReasonCode field.

Here is my eventHandler Code.

[FormControlEventHandler(formControlStr(LedgerJournalTransDaily, editReasonCode), FormControlEventType::Lookup)]
    public static void editReasonCode_OnLookup(FormControl sender, FormControlEventArgs e)
    {
        //FormControlCancelableSuperEventArgs ce = e as FormControlCancelableSuperEventArgs;
        FormRun formRun                 = sender.formRun();
        FormDataSource fds              = formRun.dataSource(formDataSourceStr(LedgerJournalTransDaily, LedgerJournalTrans));
        LedgerJournalTrans trans        = fds.cursor();
        LedgerJournalTable table        = LedgerJournalTable::find(trans.JournalNum);
        LedgerJournalName  name         = LedgerJournalName::find(table.JournalName);

        SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(ReasonTable), sender);
        QueryBuildDataSource qdbs;
        Query query;

        Info("1");
        qdbs =  query.addDataSource(tableNum(ReasonTable));
        if(name.SKEP_CarExpense == NoYes::Yes)
        {
            qdbs.addRange(fieldNum(ReasonTable,SKEP_RelatedToCarExpense)).value(queryValue(NoYes::Yes));
        }
        sysTableLookup.parmQuery(query);

        sysTableLookup.addLookupfield(fieldNum(ReasonTable, Reason));
        sysTableLookup.addLookupfield(fieldNum(ReasonTable, Description));

        sysTableLookup.performFormLookup();

        
        //ce.CancelSuperCall();
    }

I think this is the correct code. But when debugging the code, It doesn't work.

I add a breakpoint in eventHandler Code. nevertheless, it can't.

Does Method field something different from field LookUp?

Plz, Help!

I have the same question (0)
  • WillWU Profile Picture
    22,361 on at
    RE: OnLookUp Event Hanlder doesn't work.

    Hi SYCNS,

    You should not comment out the code

    FormControlCancelableSuperEventArgs ce = e asFormControlCancelableSuperEventArgs;

    ce.CancelSuperCall();

    Class FormControlCancelableSuperEventArgs is used to cancel parent event.

  • SYCNS Profile Picture
    30 on at
    RE: OnLookUp Event Hanlder doesn't work.

    I know that but the important thing is that debugger can't reach the onLookUp event handler..

  • WillWU Profile Picture
    22,361 on at
    RE: OnLookUp Event Hanlder doesn't work.

    Hi partner,

    Please try to restart IIS, and make sure the rebuild has been completed correctly.

  • nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: OnLookUp Event Hanlder doesn't work.

    "Debugger can't reach the onLookup event handler" doesn't necessarily mean that the code is not executed. Perhaps your debugger settings are not correct.

  • SYCNS Profile Picture
    30 on at
    RE: OnLookUp Event Hanlder doesn't work.

    I think its not debugger problem. The other method in same class like modified event handle is reached by debugger. i think cause of problem is field is not table field, its data method field

  • WillWU Profile Picture
    22,361 on at
    RE: OnLookUp Event Hanlder doesn't work.

    Hi SYCNS,

    Please try to use COC.

    [ExtensionOf(formControlStr(LedgerJournalTransDaily , editReasonCode))]
    final class editReasonCode_Extension
    {
    
        public void lookup()
        {
            next lookup();
    
            //your logic...
        }
    }
    

  • Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: OnLookUp Event Hanlder doesn't work.

    Hi,

    In your event handler, I don't see where you have initialized the query object.

    Is this something you haven't added to the code snippet here?

  • SYCNS Profile Picture
    30 on at
    RE: OnLookUp Event Hanlder doesn't work.

    @Will WU

    I try to use COC. But It occured error in "sysTableLookup.performFormLookup();".

    Code is

    public void lookup()

       {

           next lookup();

           SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(ReasonTable), this);

           QueryBuildDataSource qdbs;

           Query query = new Query();

           Info("1");

           qdbs =  query.addDataSource(tableNum(ReasonTable));

               qdbs.addRange(fieldNum(ReasonTable,SKEP_RelatedToCarExpense)).value(queryValue(NoYes::Yes));

           sysTableLookup.parmQuery(query);

           sysTableLookup.addLookupfield(fieldNum(ReasonTable, Reason));

           sysTableLookup.addLookupfield(fieldNum(ReasonTable, Description));

           sysTableLookup.performFormLookup();

       }

    @Gunjan Bhattacharyya

    Thank U, I forgot initialized the query Object.

    I add that code but it doesn't work neither.

    The problem is lookup EventHandler doesn't start

  • nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: OnLookUp Event Hanlder doesn't work.

    Did you notice what the error message said? Maybe it contains information that is useful in understanding the problem.

  • Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: OnLookUp Event Hanlder doesn't work.

    Did you try adding a post event handler to the ReasonFormTable::reasonCodeLookup method? You should be able to write your logic there and do a sysTableLookup.performLookup().

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,177

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 593 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans