Skip to main content

Notifications

Dynamics 365 Community / Forums / Finance forum / to create multiselecti...
Finance forum
Answered

to create multiselection lookup using extension

editSubscribe (1) ShareShare
ReportReport
Posted on by 1,416
hi , i was trying to create the multiselect lookup on form datasource i have added the field using extension but the field is not showing lookup i want to appear the value with comma seperator  , i have put the ETD NAME for the field , but it is not showing lookup can anyone please help me on this ,
below is the image of field should i use sales id etd of anything else 
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,416 on at
    to create multiselection lookup using extension
  • Layan Jwei Profile Picture
    Layan Jwei 3,079 Super User on at
    to create multiselection lookup using extension
    Hi Dinesh,

    since this question is verified. Then i advise you to create a new question.

    I didn't understand your issue well. Please create a new question and share all the details needed with screenshots.
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,416 on at
    to create multiselection lookup using extension
    hi , every one 
    how can i clear the values in the lookup , every time i have to deselected the selected values , if i backspace on the display field it will appear again in lookup , when i deselect the values it get clear , how can i clear the values using backspace . can you please guide me on this . 
     
     
    thanks,
    Regards,
    Dinesh
  • Verified answer
    Waed Ayyad Profile Picture
    Waed Ayyad 2,510 on at
    to create multiselection lookup using extension
    Hi Dinesh,
     
    Thanks for your confirmation as I tried it yesterday and it doesn't work (Add static method to form using COC and call it).
     
    Regarding your question about range, you can add range to your query by dragging dataareaId field from salesTable datasource and set the value of it to the current legal entity as in the below image:
     
    Thanks,
    Waed Ayyad
     
    If this helped, please mark it as "Verified" for others facing the same issue
     
     
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,416 on at
    to create multiselection lookup using extension
    hi waed 
    thanks for reply 
    i have removed the COc  , the code is working fine but i need to filter the query with the current data area id how can i get it done as i am getting all the sales id in lookup , can you please help me out , below is my code 
     class DTProductionOrderCustomisation_EventHandler
    {
        public static  SysLookupMultiSelectCtrl       msCtrl;
    
       // <summary>
       ///  Building the DocuType query
       //  </summary>
       ///  returns the Docutype Query
        public static Query buildDocuTypeQuery()
        {
            Query  docuTypeQry = new Query(queryStr(DTProductionOrderForSalesIdQue));
            return docuTypeQry;
        }
    
        Public static SysLookupMultiSelectCtrl  parmSysLookupMultiSelectCtrl(SysLookupMultiSelectCtrl  _msCtrl = msCtrl)
        {
            msCtrl = _msCtrl;
    
            return msCtrl;
        }
    
        Public static container getSelectedNotes(str _noteStr)
        {
            SalesTable    salesTable;
            container   tmpValues, conIds, conName;
            int         idx;
    
            if(_noteStr)
            {
                tmpValues = str2con(_noteStr, ';');
            }
    
            for(idx=1; idx<=conLen(tmpValues); idx++)
            {
                salesTable =  salesTable::find(conPeek(tmpValues, idx));
                conIds +=  salesTable.RecId;
                conName +=  salesTable.SalesId;
            }
    
            return [conIds, conName, conIds];
        }
    
       // <summary>
    
       // </summary>
       // <param name="sender"></param>
       // <param name="e"></param>
        [FormDataFieldEventHandler(formDataFieldStr(ProdTableCreate, ProdTable, DTSalesId), FormDataFieldEventType::Modified)]
        public static void DTSalesId_OnModified(FormDataObject sender, FormDataFieldEventArgs e)
        {
            SysLookupMultiSelectCtrl       msCtrlloc  = DTProductionOrderCustomisation_EventHandler::parmSysLookupMultiSelectCtrl();
            FormRun     formRun = sender.datasource().formRun();
    
            ProdTable    prodTable  =   formRun.dataSource(FormDataSourceStr(ProdTableCreate, ProdTable)).cursor() as ProdTable;
            ProdTable.DTSalesId     =   con2Str(msCtrlloc.getSelectedFieldValues(), ';');
        }
    
         //<summary>
    
         //</summary>
         //<param name="sender"></param>
         //<param name="e"></param>
        [FormEventHandler(formStr(ProdTableCreate), FormEventType::Initialized)]
        public static void ProdTableCreate_OnInitialized(xFormRun sender, FormEventArgs e)
        {
            FormRun     formRun = sender.datasource().formRun();
            Query               docuTypeQry       =   DTProductionOrderCustomisation_EventHandler::buildDocuTypeQuery();
            FormStringControl   DocuTypes         =   formRun.design().controlName('ProdTable_DTSalesId');
            ProdTable    prodTable  =   formRun.dataSource(FormDataSourceStr(ProdTableCreate, ProdTable)).cursor() as ProdTable;
    
            msCtrl   = SysLookupMultiSelectCtrl::construct(formRun,
                                                DocuTypes,
                                                querystr(DTProductionOrderForSalesIdQue),
                                                false,
                                                [tableNum(ProdTable), fieldNum(ProdTable,DTSalesId)]);
    
            msCtrl.refreshQuery(docuTypeQry);
            msCtrl.set(DTProductionOrderCustomisation_EventHandler::getSelectedNotes(ProdTable.DTSalesId));
            DTProductionOrderCustomisation_EventHandler::parmSysLookupMultiSelectCtrl(msCtrl);
        }
    
    }
     thanks ,
    Regards,
    Dinesh
  • Waed Ayyad Profile Picture
    Waed Ayyad 2,510 on at
    to create multiselection lookup using extension
    Hi Dinesh,
     
    Just to make this clear for others, how you called the parmSysLookupMultiSelectCtrl method?
     
    ProdTableCreate::parmSysLookupMultiSelectCtrl(msCtrl); OR DTProdTableCreate_ProductionOrderDetails::parmSysLookupMultiSelectCtrl(msCtrl) ;
    OR DTProdTableCreate_ProductionOrderDetails_Extension::parmSysLookupMultiSelectCtrl(msCtrl) ;

    Also, I have another comment I think you should create Event Handler class no need for COC in your case.
     
     
    Thanks,
    Waed Ayyad
  • Verified answer
    Waed Ayyad Profile Picture
    Waed Ayyad 2,510 on at
    to create multiselection lookup using extension
    Hi Dinesh,
     
    Try my last comment and your code should look like this:
    [ExtensionOf(formstr(ProdTableCreate))]
    final class DTProdTableCreate_ProductionOrderDetails_Extension
    {
        public static SysLookupMultiSelectCtrl       msCtrl;
    
        /// <summary>
        /// Building the DocuType query
        /// </summary>
        /// returns the Docutype Query
        public Query buildDocuTypeQuery()
        {
            Query  docuTypeQry = new Query(queryStr(DTProductionOrderForSalesIdQue));
            return docuTypeQry;
        }
    
        Public static SysLookupMultiSelectCtrl  parmSysLookupMultiSelectCtrl(SysLookupMultiSelectCtrl  _msCtrl = msCtrl)
        {
    
            msCtrl = _msCtrl;
    
            return msCtrl;
        }
     
        container getSelectedNotes(str _noteStr)
        {
            SalesTable    salesTable;
            container   tmpValues, conIds, conName;
            int         idx;
         
            if(_noteStr)
            {
                tmpValues = str2con(_noteStr, ';');
            }
         
            for(idx=1; idx<=conLen(tmpValues); idx++)
            {
                salesTable =  salesTable::find(conPeek(tmpValues, idx));
                conIds +=  salesTable.RecId;
                conName +=  salesTable.SalesId;
            }
         
            return [conIds, conName, conIds];
        }
    
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        [FormDataFieldEventHandler(formDataFieldStr(ProdTableCreate, ProdTable, DTSalesId), FormDataFieldEventType::Modified)]
        public static void DTSalesId_OnModified(FormDataObject sender, FormDataFieldEventArgs e)
        {
            SysLookupMultiSelectCtrl       msCtrl  = DTProdTableCreate_ProductionOrderDetails_Extension::parmSysLookupMultiSelectCtrl();
            FormRun     formRun = sender.datasource().formRun();
     
            ProdTable    prodTable  =   formRun.dataSource(FormDataSourceStr(ProdTableCreate, ProdTable)).cursor() as ProdTable;
            ProdTable.DTSalesId     =   con2Str(msCtrl.getSelectedFieldValues(), ';');
        }
    
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        [FormEventHandler(formStr(ProdTableCreate), FormEventType::Initialized)]
        public static void ProdTableCreate_OnInitialized(xFormRun sender, FormEventArgs e)
        {
            FormRun     formRun = sender.datasource().formRun();
            Query               docuTypeQry       =   formRun.buildDocuTypeQuery();
            FormStringControl   DocuTypes         =   formRun.design().controlName('ProdTable_DTSalesId');
            ProdTable    prodTable  =   formRun.dataSource(FormDataSourceStr(ProdTableCreate, ProdTable)).cursor() as ProdTable;
     
            msCtrl   = SysLookupMultiSelectCtrl::construct(formRun,
                                                DocuTypes,
                                                querystr(DTProductionOrderForSalesIdQue),
                                                false,
                                                [tableNum(ProdTable), fieldNum(ProdTable,DTSalesId)]);
     
            msCtrl.refreshQuery(docuTypeQry);
            msCtrl.set(formRun.getSelectedNotes(ProdTable.DTSalesId));
            ProdTableCreate::parmSysLookupMultiSelectCtrl(msCtrl);
    
    
        }
    
       }
    Thanks,
    Waed Ayyad
    If this helped, please mark it as "Verified" for others facing the same issue
  • Layan Jwei Profile Picture
    Layan Jwei 3,079 Super User on at
    to create multiselection lookup using extension
    Hi Dinesh,

    I didn't read all the answers so I'm not going to review your code. I will just comment on the last error you shared.
     
    You can't use non static variables inside static methods, so just make the parm method non-static like this
    Public SysLookupMultiSelectCtrl  parmSysLookupMultiSelectCtrl(SysLookupMultiSelectCtrl  _msCtrl = msCtrl)
     
    Regarding the 2nd error. You shouldn't add the "_Extension" when calling the static method, call it like this:
    DTProdTableCreate_ProductionOrderDetails::parmSysLookupMultiSelectCtrl(msCtrl) 
    but we already agreed that we will make the method non static anyways.

    And i don't think you need the parm method anyways. because it seems you are already setting the msCtrl in the init method in your original code and the msCtrl is a global variable



    Thanks,
    Layan Jweihan
    Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
  • Suggested answer
    Waed Ayyad Profile Picture
    Waed Ayyad 2,510 on at
    to create multiselection lookup using extension
    Hi,
     
    Just add static word to the public variable or you leave it without static and instead of one method to set and get the value you can add one method for set the value and one for get the value.
     
    public static SysLookupMultiSelectCtrl     msCtrl;
     
    Thanks,
    Waed Ayyad
    If this helped, please mark it as "Verified" for others facing the same issue
  • Dineshkarlekar Profile Picture
    Dineshkarlekar 1,416 on at
    to create multiselection lookup using extension
    hi , thanks for reply , but i am still having these three errors 
    i am not getting why these arror are coming .

Helpful resources

Quick Links

Take the Community feedback survey!

Answer this brief 15-question survey about your Community experience…

Demystifying Copilot: Service Edition with Sundar Raghavan

Sundar answers more questions about Copilot for Service...

Dynamics 365 Business Central vs Finance and SCM

Take a look at the key differences between Business Central and…

Leaderboard

#1
Andre Arnaud de Calavon Profile Picture

Andre Arnaud de Cal... 283,375 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 223,308 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,140

Featured topics

Product updates

Dynamics 365 release plans