web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

to create multiselection lookup using extension

(1) ShareShare
ReportReport
Posted on by 1,836
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 
I have the same question (0)
  • Dineshkarlekar Profile Picture
    1,836 on at
    below is my code please guide me on this 
    [ExtensionOf(formDataFieldStr(ProdTableCreate,ProdTable,DTSalesId))]
    final class DTProdTableCreate_ProductionOrderDetails_Extension
    {
        public SysLookupMultiSelectCtrl    multicltrl;
    
        public void lookup(FormControl _formControl, str _filterStr)
        {
    
            Query                       query;
            QueryBuildDataSource        queryBuildDataSource;
            QueryBuildFieldList         fieldList;
            FormRun                 localFormRun = _formControl.formRun();
            next lookup(_formControl,_filterStr);
    
            query                   = new Query();
            queryBuildDataSource    = query.addDataSource(tableNum(SalesTable));
            fieldList               = queryBuildDataSource.fields();
    
            fieldList.addField(fieldNum(SalesTable,SalesId));
            fieldList.addField(fieldNum(SalesTable,CustAccount));
            fieldList.dynamic(QueryFieldListDynamic::No);
    
            container   selectedField = [tableNum(SalesTable), fieldNum(SalesTable, SalesId)];
    
            multicltrl = SysLookupMultiSelectCtrl::constructWithQuery(localFormRun,_formControl,query,false,selectedField);
        }
    
        /// <summary>
    
        ///
    
        /// </summary>
    
        public void modified()
        {
            FormDataObject formDataObject = any2Object(this) as FormDataObject;
            FormDataSource formDataSource = formDataObject.datasource();
            ProdTable           prodTable;
            next modified();
    
            prodTable = formDataSource.cursor();
            prodTable.DTSalesId = con2Str(multicltrl.getSelectedFieldValues(), ';');
    
        }
    
    }
    
     
  • Suggested answer
    Waed Ayyad Profile Picture
    9,039 Super User 2025 Season 2 on at
    Hi,
     
    Try to follow the following links on how to create multiselect lookup:
     
    Regarding to your question about EDT you should not use Sales Id, as on the control you will have the selected values which will be more than the one value.
     
    Thanks,
    Waed Ayyad
    If this helped, please mark it as "Verified" for others facing the same issue
     
  • Dineshkarlekar Profile Picture
    1,836 on at
    
    [ExtensionOf(formstr(ProdTableCreate))]
    final class DTProdTableCreate_ProductionOrderDetails_Extension
    {
        public SysLookupMultiSelectCtrl       msCtrl;
    
        /// <summary>
        /// Building the DocuType query
        /// </summary>
        /// returns the Docutype Query
        public Query buildDocuTypeQuery()
        {
            Query  docuTypeQry = new Query(queryStr(DTProductionOrderForSalesIdQue));
            return docuTypeQry;
        }
     
        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;
            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)
        {
            SysLookupMultiSelectCtrl       msCtrl;
            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));
        }
    
       }
    hi i have done the code like this the multisleletion loockup is opening but when i click in select  i am getting error of object refrence please can you suggest where i have to correct in my code . i am getting all the sales id from sales table i have added sales table in query .sand dynamics fields is no and added salesid to query only .
  • Suggested answer
    Waed Ayyad Profile Picture
    9,039 Super User 2025 Season 2 on at
    Hi Dinesh,
     
    I see from your code you created 3 variable  SysLookupMultiSelectCtrl    msCtrl,
    Just define it one time on the beginning of the class and define it public and use the same variable on the on initialized and on modified event handlers it seems on the modified method your code is returning error as you are trying to call the method on null object.
     
    As in the below link:
    Thanks,
    Waed Ayyad
    If this helped, please mark it as "Verified" for others facing the same issue
  • Dineshkarlekar Profile Picture
    1,836 on at
     i have declare the SysLookupMultiSelectCtrl  in public but i am getting error 's in on initiiallize and on modifies method 
    can you please guide me on this . i have done the same in the link you provided  how can i resolve these errors 
     
  • Suggested answer
    Waed Ayyad Profile Picture
    9,039 Super User 2025 Season 2 on at
    Hi,
     
    Define it static variable or create new static method (Setter and getter to this variable), Like param method.
     
    Public static SysLookupMultiSelectCtrl  parmSysLookupMultiSelectCtrl(SysLookupMultiSelectCtrl  _msCtrl = msCtrl)
    
    {
    
      msCtrl= _msCtrl;
    
      return msCtrl;
    
    }
    and you should set the variable on each method that set the variable.
     
    Thanks,
    Waed Ayyad
    If this helped, please mark it as "Verified" for others facing the same issue
     
  • Dineshkarlekar Profile Picture
    1,836 on at
    [ExtensionOf(formstr(ProdTableCreate))]
    final class DTProdTableCreate_ProductionOrderDetails_Extension
    {
        public 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];
        }
      
    
        public void init()
        {
            next init();
            Query               docuTypeQry       =   this.buildDocuTypeQuery();
            FormStringControl   DocuTypes         =   this.design().controlName('ProdTable_DTSalesId');
            ProdTable    prodTable  =   this.dataSource(FormDataSourceStr(ProdTableCreate, ProdTable)).cursor() as ProdTable;
    
            msCtrl   = SysLookupMultiSelectCtrl::construct(this,
                                                    DocuTypes,
                                                    querystr(DTProductionOrderForSalesIdQue),
                                                    false,
                                                    [tableNum(ProdTable), fieldNum(ProdTable,DTSalesId)]);
            msCtrl.refreshQuery(docuTypeQry);
            msCtrl.set(this.getSelectedNotes(ProdTable.DTSalesId));
        }
    
    }
     
     I am getting the lookup open and able to select the values but when i click on the select in lookup the values does not appear in field field is blank  and i am getting below error with parmsyslookupmultiselectcontrol 
     plese suggest me how can i get them resolve modified event is still having issue .
  • Suggested answer
    Waed Ayyad Profile Picture
    9,039 Super User 2025 Season 2 on at
    Hi,
     
    You don't do what I asked you to do, What I meant is in the below code:
    [ExtensionOf(formstr(ProdTableCreate))]
    final class DTProdTableCreate_ProductionOrderDetails_Extension
    {
        public 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
  • Dineshkarlekar Profile Picture
    1,836 on at
    hi , thanks for reply , but i am still having these three errors 
    i am not getting why these arror are coming .
  • Suggested answer
    Waed Ayyad Profile Picture
    9,039 Super User 2025 Season 2 on at
    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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 664 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 522 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 303 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans