Error in worker lookup

This is my issue. I have a dialog field “Worker”. I used “HcmWorkerRecId” EDT for this dialog field for lookup. By default, the lookup will display all workers, employees and etc. so I modified the lookup to limit the list in the dropdown. I used the code below to modify the lookup.

void Fld2_1_DirPerson_FK_Name_lookup()

{

FormControl formControl = dlgworkerId.dialog().formRun().controlCallingMethod();

;

HcmWorkerLookup::newCustomOptions(false, // _includeEmployees

true, // _includeContractors

true, // _includeActive

false, // _includePending

true, // _includeTerminated

true, // _includeOnlyCurrentLegalEntity

true, // _lockWorkerTypeFilters

true, // _lockWorkerStatusFilters

true // _lockLegalEntityFilters

).lookupWorker(formControl);

}

When I tested the lookup, it works fine and it filters data according to the requirement. See screenshot below.

But when trying to select a record in the lookup and click OK, I am getting a message below and won’t allow me to continue. I tried researching but no luck for me. Hope you can help me.

0020.rc12.PNG

4810.rc13.PNG

Looking forward to hear from you.

Regards,

AML

Split from another thread created by another user about another problem.

First of all, you’re overriding a wrong method. The control is a reference group, therefore you should override lookupReference(), not lookup(). That’s the bug.

Also, you’re overriding the method in a wrong way - you forgot that AX 2012 has registerOverrideMethod(). Here you have a complete, standalone example:

Class1
{
    public static void main(Args args)
    {
        new Class1().prompt();
    }

    private void prompt()
    {
        Dialog dialog = new Dialog();
        DialogField df = dialog.addField(extendedTypeStr(HcmWorkerRecId));
        df.registerOverrideMethod(methodStr(FormReferenceControl, lookupReference),
                                  methodStr(Class1, lookupWorker),
                                  this);
        dialog.run();
    }

    private void lookupWorker(FormReferenceControl _referenceControl)
    {
        HcmWorkerLookup::newCustomOptions(...).lookupWorker(_referenceControl);
    }
}

Hi Martin,

Thank you very much for your response, really appreciate it.

I did try your recommendation, lookup is working but it displays all the record, the requirement is like in the screenshot below showing only Contractors, Employed and terminated and Current legal entity. How can I achieve this?

Regards,

AML

You you saying that my code doesn’t work, or that your code doesn’t work?

The picture is not from my solution, therefore I assume you didn’t apply my code correctly. Please debug your code - ensure yourself that the overridden method gets called and that you call newCustomOptions() with the right parameters.

Hi Martin,

My code doesn’t work. Will try to debug and update you soon.

Regards,

AML

Hi Martin,

I was able to determine what is causing the issue. The issue is that, I have overridden the dialogPostRun() method that is why code is not working. After removing the method in my class, the code works perfectly. Thank you very much Martin.