Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

lookup opening on second click

(0) ShareShare
ReportReport
Posted on by 1,629
I have created multiselect lookup on custom from , on first click it is not opening on second click it opens, when i debug is saw there on first click it does not open but it check through all the code not error nothing it shows but in second click it gets open. Can you please help me on this , it should open in first click .below is my code  ,before that is is going to class systemnotificationmanager this mehtod  the method return blank value. it looks like it loads on first time and second time when i click it directly opens, at that time debugger does not hit .
[Form]
public class EmployeePayrollDetails extends FormRun
{

    SysLookupMultiSelectCtrl  msLookupCtrl;
    List selectedCompanies;


    [Control("String")]
    class CompanyName
    {
        /// <summary>
        ///
        /// </summary>
        public void lookup()
        {
            super();
            
            OMUserRoleOrganization omOrg;
            SecurityUserRole      securityUserRole,securityUserRole1;
            SecurityRole          securityRole,securityRole1;
          
           while select firstonly securityUserRole
                join securityRole
              where securityUserRole.SecurityRole == securityRole.RecId
                && securityUserRole.User == curUserId()
                && (securityRole.Name == 'HR & Payroll Consolidated Reports'
                || securityRole.Name == 'HR Consolidated Reports' )
            {
                select firstonly omOrg
                where omOrg.User == curUserId()
                && omOrg.SecurityRole == securityUserRole.SecurityRole;
               
                if(omOrg.RecId)
                    break;
                
            }
        

            Query query = new Query();
            QueryBuildDataSource qbdsCompany = query.addDataSource(tablenum(CompanyInfo));
    
            qbdsCompany.addSelectionField(fieldNum(CompanyInfo, DataArea));
            qbdsCompany.addSelectionField(fieldNum(CompanyInfo, Name));
             
            if(securityUserRole && omOrg)
            {
                    QueryBuildDataSource qbdsOrg = qbdsCompany.addDataSource(tablenum(OMUserRoleOrganization));
                    qbdsOrg.relations(false);
                qbdsOrg.joinMode(JoinMode::ExistsJoin);
                    qbdsOrg.addLink(
                   fieldnum(OMUserRoleOrganization, omInternalOrganization),
                   fieldnum(CompanyInfo, RecId));

        
                    qbdsOrg.addRange(fieldnum(OMUserRoleOrganization, User)).value(queryValue(curUserId()));
                qbdsOrg.addRange(fieldnum(OMUserRoleOrganization, SecurityRole)).value(queryValue(securityUserRole.SecurityRole));

            }

            msLookupCtrl = SysLookupMultiSelectCtrl::constructWithQuery(this.formRun(), this, query);
            msLookupCtrl.set(msLookupCtrl.getSelectedFieldValues());

        }

    }
}
 
  • Suggested answer
    Waed Ayyad Profile Picture
    8,606 Super User 2025 Season 1 on at
    lookup opening on second click
     
    From where you added this method buildCompanyQuery(); ?  You should replace it with the query that returns the values that you want.
     
    Query                   query = new Query();
    QueryBuildDataSource    qbds;
    CompanyInfo             companyInfo;
    
    qbds = query.addDataSource(tableNum(CompanyInfo));
    qbds.addRange(fieldNum(CompanyInfo, Name))
     
     

    Thanks,

    Waed Ayyad

    If this helped, please mark it as "Verified" for others facing the same issue

  • Dineshkarlekar Profile Picture
    1,629 on at
    lookup opening on second click
    hi @everyone
    i am getting  error for this line , what should i put here.
    please let me know
     
     // Build initial query
        Query query = buildCompanyQuery();
    Error        The name 'buildCompanyQuery' does not denote a predefined function,  a static method on the Global class nor a previously defined local function.    
  • Waed Ayyad Profile Picture
    8,606 Super User 2025 Season 1 on at
    lookup opening on second click
    Hi,
     
    Remove the super () call from the Lookup method as Martin said, also why do you have Break without While loop?
     
     
     
     
     
     
    Thanks,
    Waed Ayyad
  • Dineshkarlekar Profile Picture
    1,629 on at
    lookup opening on second click
    Hi,
    Thanks for reply ,
    I have done like this below is my code , please corect me if i am wrong 
    [Form]
    public class EmployeePayrollDetails extends FormRun
    {
    
        SysLookupMultiSelectCtrl  msLookupCtrl;
        List selectedCompanies;
    
    
    public void init()
    {
        super();
    
        // Build initial query
        Query query = buildCompanyQuery();
    
        // Initialize the multiselect control ONCE here
        msLookupCtrl = SysLookupMultiSelectCtrl::constructWithQuery(
            this,
            element.design().controlName(formControlStr(EmployeePayrollDetails, CompanyName)),
            query
        );
    }
    
    
    
    
    
        [Control("String")]
        class CompanyName
        {
            /// <summary>
            ///
            /// </summary>
            public void lookup()
            {
                super();
                
                OMUserRoleOrganization omOrg;
                SecurityUserRole      securityUserRole,securityUserRole1;
                SecurityRole          securityRole,securityRole1;
              
                select firstonly FROM securityUserRole
                    join securityRole
                  where securityUserRole.SecurityRole == securityRole.RecId
                    && securityUserRole.User == curUserId()
                    && (securityRole.Name == 'HR & Payroll Consolidated Reports'
                    || securityRole.Name == 'HR Consolidated Reports' )
               
                    select firstonly omOrg
                    where omOrg.User == curUserId()
                    && omOrg.SecurityRole == securityUserRole.SecurityRole;
                   
                    if(omOrg.RecId)
                        break;
                    
           
            
    
                Query query = new Query();
                QueryBuildDataSource qbdsCompany = query.addDataSource(tablenum(CompanyInfo));
        
                qbdsCompany.addSelectionField(fieldNum(CompanyInfo, DataArea));
                qbdsCompany.addSelectionField(fieldNum(CompanyInfo, Name));
                 
                if(securityUserRole && omOrg)
                {
                        QueryBuildDataSource qbdsOrg = qbdsCompany.addDataSource(tablenum(OMUserRoleOrganization));
                        qbdsOrg.relations(false);
                    qbdsOrg.joinMode(JoinMode::ExistsJoin);
                        qbdsOrg.addLink(
                       fieldnum(OMUserRoleOrganization, omInternalOrganization),
                       fieldnum(CompanyInfo, RecId));
    
            
                        qbdsOrg.addRange(fieldnum(OMUserRoleOrganization, User)).value(queryValue(curUserId()));
                    qbdsOrg.addRange(fieldnum(OMUserRoleOrganization, SecurityRole)).value(queryValue(securityUserRole.SecurityRole));
    
                }
    
                msLookupCtrl.set(msLookupCtrl.getSelectedFieldValues());
    
            }
    
        }
    }
     
  • Martin Dráb Profile Picture
    234,449 Most Valuable Professional on at
    lookup opening on second click
    I think the main problem is that your first run a lookup (by calling super()) and only then you initialize SysLookupMultiSelectCtrl. Change that.
     
    The usual approach is initializing SysLookupMultiSelectCtrl only once in init(), not repeatedly every time you open the lookup.
     
    What the purpose of this code?
     
    msLookupCtrl.set(msLookupCtrl.getSelectedFieldValues());
    It doesn't make sense to me.
     
    "while select firstonly" doesn't make a good sense and your query may give you a wrong result. Join OMUserRoleOrganization with SecurityUserRole and use a regular select returning a single row.
     
    Is GetWhatsNewNotifications() related to the topic in any way? If not, please remove it. Confusing others with unrelated code isn't in your interest.
  • Suggested answer
    Saalim Ansari Profile Picture
    569 on at
    lookup opening on second click

    Hi @Dineshkarlekar,


    On the first click, your control is not fully initialized or the SysLookupMultiSelectCtrl::constructWithQuery() method is being called after the control’s event has passed, or with an uninitialized context (e.g., empty query, no selectedFields, no formRun() context). Then on the second click, the control is already initialized (cached or persisted) and so it opens as expected.

     

    Move the initialization of the SysLookupMultiSelectCtrl from the lookup() method to the init() or run() method of the form, and call .set() in lookup() only if needed. The lookup() method is too late in the lifecycle to construct the lookup control fully — constructWithQuery should ideally be called once, and only once.

    You can see an example in ERMultiselectParameterUIBuilder.initMultiselectControl(), for instance.

     

    Hope this helps
    Saalim

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

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

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

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 565

#2
Martin Dráb Profile Picture

Martin Dráb 536 Most Valuable Professional

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 402 Super User 2025 Season 1

Product updates

Dynamics 365 release plans