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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

lookup based on condition doesn't work directly and the UI for both lookups is different

(0) ShareShare
ReportReport
Posted on by 2,003

Hi,

I have this lookup code:

    /// 
    ///
    /// 
    /// 
    /// 
    [FormControlEventHandler(formControlStr(CaseDetailCreate, AAWorker), FormControlEventType::Lookup)]
    public static void AAWorker_OnLookup(FormControl sender, FormControlEventArgs e)
    {
        FormStringControl customerContract = sender.formRun().design().controlName(formControlStr(CaseDetailCreate, AACustomerContract)) as FormStringControl;

        if(customerContract.text() != '')
        {
            SysLookupMultiSelectCtrl multiSelectCtrl;
            Query query = new Query();
            QueryBuildDataSource qbds = query.addDataSource(tableNum(ResourceView));
            QueryBuildDataSource qbds1 = qbds.addDataSource(tableNum(PROJVALEMPLPROJSETUP));
            Qbds1.joinMode(JoinMode::InnerJoin);
            Qbds1.addLink(fieldNum(ResourceView, RecId), fieldNum(PROJVALEMPLPROJSETUP, Resource));
            QueryBuildDataSource qbds2 = qbds1.addDataSource(tableNum(AATable1));
            qbds2.joinMode(JoinMode::InnerJoin);
            qbds2.addLink(fieldNum(PROJVALEMPLPROJSETUP, ProjId), fieldNum(AATable1, OrderNumber));
            qbds2.addRange(fieldNum(AATable1, OrderNumber)).value(queryValue(customerContract.text()));

            qbds.addSelectionField(FieldNum(ResourceView, ResourceId));
            qbds.addSelectionField(FieldNum(ResourceView, Name));
            multiSelectCtrl = SysLookupMultiSelectCtrl::constructWithQuery(sender.formRun(), sender, query);
        }
        else
        {
            SysLookupMultiSelectCtrl multiSelectCtrl;
            Query query = new Query();
            QueryBuildDataSource qbds = query.addDataSource(tableNum(HcmWorkerDetailsView));
            qbds.addSelectionField(FieldNum(HcmWorkerDetailsView, PersonnelNumber));
            qbds.addSelectionField(FieldNum(HcmWorkerDetailsView, Name));
            multiSelectCtrl = SysLookupMultiSelectCtrl::constructWithQuery(sender.formRun(), sender, query);
        }
    }


1. the lookup field is on a dialog, and as you can see the lookup depends on another form control. When the dialog is still open, if i change the value of the control to match the other lookup it doesn't work, it keeps showing the old one until i close the dialog and open it again... how to solve this?

2. The UI for both lookups is different, why? i want them both to be the same things, as you can see for the hcmworkerDetailsView i only selected 2 fields but i can still see a lot of fields
pastedimage1665949595818v1.png

however the other lookup looks good and smaller in size.. why is that?
pastedimage1665949750276v2.png

I have the same question (0)
  • Community Member Profile Picture
    on at

    Hi,

    1. Please try to debug and see what values you are getting from the control.
    2. Use the following code to disable dynamic fields on your other datasources which will then not be included in the lookup fields:
      queryBuildDataSource.fields().dynamic(NoYes::No);

    Regards,

    Kamal

  • .. Profile Picture
    2,003 on at

    Hi Kamal,

    1.As for the debug point. When I first opened the dialog form, and clicked on the lookup, the eventhandler was called, when I clicked on the lookup again, the event handler wasn't called. Why is that? and the UI is still different

    2. The dynamics field didn't work

     else
            {
                SysLookupMultiSelectCtrl multiSelectCtrl;
                Query query = new Query();
                QueryBuildDataSource qbds = query.addDataSource(tableNum(HcmWorkerDetailsView));
                qbds.addSelectionField(FieldNum(HcmWorkerDetailsView, PartyNumber));
                qbds.addSelectionField(FieldNum(HcmWorkerDetailsView, Name));
                qbds.fields().dynamic(NoYes::No);
                multiSelectCtrl = SysLookupMultiSelectCtrl::constructWithQuery(sender.formRun(), sender, query);
            }

    3. Now since I filled multiple selects in the control. I want on the clicked method to insert those workers in the caseAssociation grid.. how can I get each value from the multi select?

  • GirishS Profile Picture
    27,843 Moderator on at

    Hi IntegrationBeginner,

    You need to make use of getSelectedFieldValues method of SysLookupMultiSelectCtrl class to get the selected values line below.

    Container con;
    con = multiSelectCtrl.getSelectedFieldValues();

    It will return as container and you can loop through the values.

    Thanks,

    Girish S.

  • .. Profile Picture
    2,003 on at

    Hi Girish,

    I want to get the values from another control and not in the lookup method.

    so in another control clicked method i want to loop through the multi selected values in another control. How to do that?

  • Suggested answer
    GirishS Profile Picture
    27,843 Moderator on at

    Hi IntegrationBeginner,

    If you declare the SysLookupMultiSelectCtrl multiSelectCtrl globally which means in the form declaration itself, you can access the buffer in any if the form methods.

    Thanks,

    Girish S.

  • .. Profile Picture
    2,003 on at

    Hi Girish,

    How about the extra fields appearing in the lookup?

    even though i specified only 2 fields using addSelectionField but alot are appearing as i described in previous comments

  • GirishS Profile Picture
    27,843 Moderator on at

    SysLookupMultiSelectCtrl::constructQuery arguments takes the container as parameter for showing fields in the lookup. Try passing the required fields to that and check.

    multiSelectCtrl = SysLookupMultiSelectCtrl::constructWithQuery(sender.formRun(), sender, query,
    [tableNum(TableName), fieldNum(TableName,FieldName)]));

    Thanks,

    Girish S.

  • .. Profile Picture
    2,003 on at

    Hi Girish,

    So you don't want me to use add selection field, right?

    can you give me the syntax exactly for multiple fields as i'm getting errors on it

     multiSelectCtrl = SysLookupMultiSelectCtrl::constructWithQuery(sender.formRun(), sender, query, false, [(tableNum(ResourceView), fieldNum(ResourceView,ResourceId)), (tableNum(ResourceView), fieldNum(ResourceView,Name)));

    here's what i did:

        [FormControlEventHandler(formControlStr(CaseDetailCreate, AAWorker), FormControlEventType::Lookup)]
        public static void AAWorker_OnLookup(FormControl sender, FormControlEventArgs e)
        {
            FormStringControl customerContract = sender.formRun().design().controlName(formControlStr(CaseDetailCreate, AACustomerContract)) as FormStringControl;
    
    
            SysLookupMultiSelectCtrl multiSelectCtrl;
            Query query = new Query();
            QueryBuildDataSource qbds = query.addDataSource(tableNum(ResourceView));
            QueryBuildDataSource qbds1 = qbds.addDataSource(tableNum(PROJVALEMPLPROJSETUP));
            qbds1.joinMode(JoinMode::InnerJoin);
            qbds1.addLink(fieldNum(ResourceView, RecId), fieldNum(PROJVALEMPLPROJSETUP, Resource));
            QueryBuildDataSource qbds2 = qbds1.addDataSource(tableNum(Table1));
            qbds2.joinMode(JoinMode::InnerJoin);
            qbds2.addLink(fieldNum(PROJVALEMPLPROJSETUP, ProjId), fieldNum(Table1, OrderNumber));
            qbds2.addRange(fieldNum(Table1, OrderNumber)).value(queryValue(customerContract.text()));
    
            //qbds.addSelectionField(FieldNum(ResourceView, ResourceId));
            //qbds.addSelectionField(FieldNum(ResourceView, Name));
            multiSelectCtrl = SysLookupMultiSelectCtrl::constructWithQuery(sender.formRun(), sender, query, false, [(tableNum(ResourceView), fieldNum(ResourceView,ResourceId)), (tableNum(ResourceView), fieldNum(ResourceView,Name))]);
            FormRun formRun = sender.formRun();
            formRun.AAMultiSelectCtrl(multiSelectCtrl);
            
    
        }

  • GirishS Profile Picture
    27,843 Moderator on at

    Yo already said that adding selection field doesn't work. That's why I have given an alternate suggestion.

    Try the below code.

    container selectedFields = [tableNum(ResourceView),fieldnum(ResourceView,ResourceId),fieldnum(ResourceView,Name)];
    multiSelectCtrl = SysLookupMultiSelectCtrl::constructWithQuery(sender.formRun(), 
    sender, 
    query, 
    false, 
    selectedFields);

    Thanks,

    Girish S.

  • GirishS Profile Picture
    27,843 Moderator on at

    Edited the code. You can initialize container and add fields to that.

    Thanks,

    Girish S.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

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

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 689

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 606 Super User 2026 Season 1

#3
CP04-islander Profile Picture

CP04-islander 356

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans