Thursday, 9 September 2021

lookupReference method on form data source field in AX / X++

 public Common lookupReference(FormReferenceControl _formReferenceControl)
{
    HcmWorker HcmWorker;
    Query query = new Query();
    QueryBuildRange         queryBuildRange, qbr1;
    QueryBuildDataSource    qbds, qbds1, qbds2, qbds3, qbds4, qbds5;
    SysReferenceTableLookup sysTableLookup;
    qbds = query.addDataSource(tableNum(HcmWorker));
    qbds1 = qbds.addDataSource(tableNum(DirAddressBookPartyView));
    qbds1.addLink(fieldNum(DirAddressBookPartyView,RecId),fieldNum(HcmWorker, Person));
    qbds2= qbds1.addDataSource(tableNum(RetailStoreAddressBook));
                     qbds2.addLink(fieldNum(RetailStoreAddressBook,AddressBook),fieldNum(DirAddressBookPartyView,AddressBook));

    qbds3= qbds2.addDataSource(tableNum(RetailStoreTable));
    qbds3.addLink(fieldNum(RetailStoreTable,RecId),fieldNum(RetailStoreAddressBook,StoreRecId));
    qbds4 =qbds3.addDataSource(tableNum(LedgerJournalName));
    qbds4.addLink(fieldNum(LedgerJournalName, SL_RetailStoreId),fieldNum(RetailStoreTable,StoreNumber));

    sysTableLookup = SysReferenceTableLookup::newParameters(tableNum(HcmWorker), _formReferenceControl, true);
    sysTableLookup.addLookupField(fieldNum(HcmWorker,personnelNumber));
    sysTableLookup.addLookupField(fieldNum(HcmWorker, Person));

    qbr1 = qbds2.addRange(fieldNum(RetailStoreAddressBook,AddressBookType));
    qbr1.value(queryValue(RetailAddressBookType::Employee));

    queryBuildRange = qbds4.addRange(fieldNum(LedgerJournalName,JournalName));
    queryBuildRange.value(queryValue(journalName));

    sysTableLookup.parmQuery(query);

    return sysTableLookup.performFormLookup();
}

No comments:

Post a Comment

Difference Between Edit And Display Method in Ax

Display Method: The display method means that the method’s return value is being displayed on a form or a report.  This value is fixed and c...