25 July 2022

Query with group by and joins in lookup D365FO

 [FormControlEventHandler(formControlStr(TRGSysMailerMessageEditor, TRGTo), FormControlEventType::Lookup)]

    public static void TRGTo_OnLookup(FormControl sender, FormControlEventArgs e)

    {

        TRGSysMailerExchange   sysMailerExchange   = sender.formRun().args().caller() as TRGSysMailerExchange;

        CustAccount         custAccount         = sysMailerExchange.parmAccountNum();        Query query = new Query();

        QueryBuildDataSource qbds,qbds1,qbds2,qbds3,qbds4,qbds5;

        qbds = query.addDataSource(tableNum(LogisticsLocationRole));

        qbds.addSelectionField(FieldNum(LogisticsLocationRole,Name));

        qbds.orderMode(ordermode::GroupBy);

        qbds.addSortField(FieldNum(LogisticsLocationRole,Name));

        qbds1 = qbds.addDataSource(tableNum(LOGISTICSELECTRONICADDRESSROLE));

        qbds1.joinMode(JoinMode::InnerJoin);

        qbds1.addLink(fieldNum(LOGISTICSLOCATIONROLE,RecId),fieldNum(LOGISTICSELECTRONICADDRESSROLE,LOCATIONROLE));

        qbds2 = qbds1.addDataSource(tableNum(CustTable));

        //qbds2.addRange(fieldNum(CustTable, AccountNum)).value(queryValue(custAccount));

        qbds3 = qbds2.addDataSource(tableNum(DIRPARTYCONTACTINFOVIEW));

        //qbds3.addRange(fieldNum(DIRPARTYCONTACTINFOVIEW, Type)).value(queryValue(LogisticsElectronicAddressMethodType::Email));

        qbds3.joinMode(JoinMode::InnerJoin);

        qbds3.addLink(fieldNum(CustTable,Party),fieldNum(DIRPARTYCONTACTINFOVIEW,party));

        qbds4 = qbds3.addDataSource(tableNum(LOGISTICSELECTRONICADDRESS));

        qbds4.joinMode(JoinMode::InnerJoin);

        qbds4.addLink(fieldNum(DIRPARTYCONTACTINFOVIEW,ELECTRONICADDRESS),fieldNum(LOGISTICSELECTRONICADDRESS,RecId));

        SysTableLookup      sysTableLookup  = SysTableLookup::newParameters(tableNum(LogisticsLocationRole), sender);

        sysTableLookup.addLookupfield(fieldNum(LogisticsLocationRole, Name));        sysTableLookup.parmQuery(query);

        sysTableLookup.performFormLookup();        //cancel the call to super() to prevent the system from trying to show        //the lookup form twice and cause an error.

        FormControlCancelableSuperEventArgs cancelableSuperEventArgs = e as FormControlCancelableSuperEventArgs;

        cancelableSuperEventArgs.CancelSuperCall();

    }

No comments:

Post a Comment

Give me the commetns and solutions

Ledger Voucher creation Framework and x++ code to create ledger voucher

 Please click her for MS reference file Below is the out of the box example reference and code. SalesInvoiceJournalPostSubBill_Extension-...