29 July 2022

Multi Select Lookup in Forms with Filters in D365 / Custom multi select lookup in form D365FO

Standard User dimension 1 dropdown. Multi-selection will be allowed in these dropdowns. Multiple selected values will be stored in the field, separated by semi-colon (;).



LookUp code 

     


Event handler class to get the  multi select lookup   


class TRGReqTransPOEventHandler


{    

    [FormControlEventHandler(formControlStr(ReqTransPo,TRGSite), FormControlEventType::Lookup),


        SuppressBPWarning('BPParameterNotUsed','Parameter required by the event method')]


    public static void TRGSite_OnLookup(FormControl sender, FormControlEventArgs e)


    {

        Query                   query = new Query();

        QueryBuildDataSource    queryBuildDataSource;  

        container            selectFieldPurchRef = [tableNum(InventSite), fieldNum(InventSite, SiteId)];

        FormRun             fr = sender.formRun();


        queryBuildDataSource = query.addDataSource(tableNum(InventSite));

        queryBuildDataSource.addSelectionField(fieldNum(InventSite, SiteId));

        queryBuildDataSource.orderMode(ordermode::GroupBy);

        queryBuildDataSource.addSortField(FieldNum(InventSite,SiteId));


        SysLookupMultiSelectCtrl::constructWithQuery(fr,sender,query,false,selectFieldPurchRef);


    }


    [FormControlEventHandler(formControlStr(ReqTransPo, TRGSalesId), FormControlEventType::Lookup),


    SuppressBPWarning('BPParameterNotUsed','Parameter required by the event method')]


    public static void TRGSalesId_OnLookup(FormControl sender, FormControlEventArgs e)


    {


        Query                       query = new Query();

        QueryBuildDataSource        queryBuildDataSource;


        container                   selectFieldPurchRef = [tableNum(TRGReqTransView), fieldNum(TRGReqTransView, InventDimension3)];

        FormRun                     fr = sender.formRun();

        queryBuildDataSource        = query.addDataSource(tableNum(TRGReqTransView));

        queryBuildDataSource.addSelectionField(fieldNum(TRGReqTransView, InventDimension3));

        queryBuildDataSource.orderMode(ordermode::GroupBy);

        queryBuildDataSource.addSortField(FieldNum(TRGReqTransView, InventDimension3));

        queryBuildDataSource.addRange(fieldNum(HDMReqTransView, InventDimension3)).value(SysQuery::valueNotEmptyString());


        SysLookupMultiSelectCtrl::constructWithQuery(fr,sender,query,false,selectFieldPurchRef);


    }

    [FormControlEventHandler(formControlStr(ReqTransPo, TRGSite), FormControlEventType::Modified),


        SuppressBPWarning('BPParameterNotUsed','Parameter required by the event method')]


    public static void TRGSite_OnModified(FormControl sender, FormControlEventArgs e)


    {

        FormRun fr = sender.formRun();

        FormDataSource formDataSourceId  = fr.dataSource(formDataSourceStr(ReqTransPo, InventDim));

        FormDataSource formDataSource  = fr.dataSource(formDataSourceStr(ReqTransPo, ReqPO));

        formDataSourceId.executeQuery();

        formDataSource.executeQuery();

    }

}


-----------------------------------------------------------------------------------------------------------------------------


On Modified :


    


-----------------------------------------------------------------------------------------------------------------------------


[ExtensionOf(formdatasourcestr(ReqTransPO,InventDim))]


internal final class TRGReqTransPOInventDimDS_Extension

{    


    public void executeQuery()

    {           

        #characters

        FreeText1000 siteId = this.formRun().design().controlName(formControlStr(ReqTransPo,TRGSite)).valueStr();

        FreeText1000 salesId = this.formRun().design().controlName(formControlStr(ReqTransPo,TRGSalesId)).valueStr();

        QueryBuildRange siteQBR,salesIdQBR;

        siteQBR = sysquery::findorcreaterange(this.queryBuildDataSource(),fieldnum(InventDim,InventSiteId));

        salesIdQBR = sysquery::findorcreaterange(this.queryBuildDataSource(),fieldnum(InventDim,InventDimension3));


        if (siteId)

        {

            siteQBR.value(strReplace(siteId,#semicolon,#comma));

        }

        else

        {

            siteQBR.value(SysQuery::valueUnlimited());

        }

        if (salesId)

        {

            salesIdQBR.value(strReplace(salesId,#semicolon,#comma));

        }

        else

        {

            salesIdQBR.value(SysQuery::valueUnlimited());

        }

        next executeQuery();

    }

}


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->...