Wednesday, March 20, 2019

Reference Group Control lookup in D365

This post shows how to create lookup for ReferenceGroupControl using extensions.

All we need to do is to register event handler for lookup function and make a lookup little bit differently as shown below.


After handler is registered use the following code.

[FormControlEventHandler(formControlStr(MyWorker, MyWorker_HcmWorkerRecId), FormControlEventType::Lookup)]
public static void MyWorker_HcmWorkerRecId_OnLookup(FormControl sender, FormControlEventArgs e)
{
    MyClass::createLookup(sender);

    FormControlCancelableSuperEventArgs cancelableArgs = e as FormControlCancelableSuperEventArgs;
    cancelableArgs.CancelSuperCall();
}

private static void createLookup(FormReferenceGroupControl _ctrl)
{
    SysReferenceTableLookup sysTableLookup = SysReferenceTableLookup::newParameters(tablenum(HcmWorker), _ctrl);
    Query                   query = new Query();

    sysTableLookup.addLookupfield(fieldNum(HcmWorker, PersonnelNumber));
   
    query.addDataSource(tablenum(HcmWorker));
    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
}

Changin NewRecordAction through extensions

In this post we will discuss how to change NewRecordAction property using extensions in D365 for Finance and Operations.

As you know NewRecordAction property is not enabled when being used in extensions as shown in the picture below.


Resolution: 

This can be achieved by capturing onInitialized form handler event as shown below.