Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Answered

How to Create a Dropdown with ReferenceGroup to Display Specific Data Only

(3) ShareShare
ReportReport
Posted on by 342

Hello everyone,

I have a specific scenario I want to implement. I have two tables: the first one is called ViolationGroup and the second one is ViolationTypes. In the first table, I have two fields: GroupCode and Description. Similarly, in the second table, I have ViolationCode and ViolationType, as well as a field that should be linked to the RecId of the ViolationGroup table.

I also have a form with a grid bound to the ViolationTypes table. I defined the fields of the ViolationTypes table in the grid. When I reached the GroupCode field, I wanted to create a dropdown list that displays all the data from ViolationGroup, and upon selecting any ViolationGroup, only the GroupCode should be displayed.

Here’s the code I implemented:
 

SysTableLookup sysTableLookup = SysTableLookup::newParameters(tablenum(ViolationGroup), sender);  
Query query = new Query();  

sysTableLookup.addLookupfield(fieldNum(ViolationGroup, ViolationGroupCode), true);  
sysTableLookup.addLookupfield(fieldNum(ViolationGroup, ViolationGroupDescription));  

QueryBuildDataSource qbds = query.addDataSource(tablenum(ViolationGroup));  
sysTableLookup.parmQuery(query);  

sysTableLookup.performFormLookup();  

FormControlCancelableSuperEventArgs ce = e as FormControlCancelableSuperEventArgs;  
ce.CancelSuperCall();  

However, the RecId of the field is still being displayed, so I resorted to using a Reference Group by following the instructions in this video:
https://www.youtube.com/watch?v=vpRrNL-GfbY

This was a suitable solution but not an optimal one. What I want is to display all the data from the ViolationGroup table, and upon selecting any field, only the field I specify (like GroupCode) should be displayed. However, the Reference Group tool displays the fields I’ve defined in the index of the table it’s linked to.

What I want to achieve is the ability to display all the data from the table using a Reference Group while maintaining the display of GroupCode in the cell—exactly as it works when selecting a customer in the Sales Order form.

I hope I’ve explained my issue clearly. If anything is unclear or needs further clarification, please let me know so I can elaborate further.

Categories:
  • Waed Ayyad Profile Picture
    Waed Ayyad 7,257 Super User 2025 Season 1 on at
    How to Create a Dropdown with ReferenceGroup to Display Specific Data Only
     
    No need to apologize; I know my answer got replicated suddenly on many answers; I don't know why, but our purpose as a community here is to answer your inquiries.

    Thanks,
    Waed Ayyad
     
     
  • Ali AbdAlNasser Profile Picture
    Ali AbdAlNasser 342 on at
    How to Create a Dropdown with ReferenceGroup to Display Specific Data Only
    I also thank @Waed Ayyad for his help in solving this issue, and it seems that the entire mistake was on my part because I did not understand his response well. I truly apologize.
  • Ali AbdAlNasser Profile Picture
    Ali AbdAlNasser 342 on at
    How to Create a Dropdown with ReferenceGroup to Display Specific Data Only
    Hello @Layan Jwei.  
    I am really grateful to you for this solution; it has worked very well and is the ideal solution I was looking for. However, it seems that I didn't fully understand your intention earlier. I truly apologize for that.
  • Verified answer
    Layan Jwei Profile Picture
    Layan Jwei 7,679 Super User 2025 Season 1 on at
    How to Create a Dropdown with ReferenceGroup to Display Specific Data Only
    Hi Ali,
     
    I already explained to you twice how to add multiple fields
     
    I will copy my previous answer
     
    Regarding your last question, If you need to add more than title1 and title2 fields in the lookup, then it's either you play with the standard autoLookup field group OR in a complex case, you will need to add x++ code.
     
    By default, if you leave the autoLookup field group as empty, it willl return title1 and title2 fields, in addition to the first field in the the first unique index (in ur case title1 and the first field in the first unique index is the same which is groupCode)
     
    Now if you want more fields to appear, you can add in the standard autoLookup field group manually the following:
    GroupCode, Description, extra field1, extra field2...etc
  • Ali AbdAlNasser Profile Picture
    Ali AbdAlNasser 342 on at
    How to Create a Dropdown with ReferenceGroup to Display Specific Data Only
    Hi @Layan Jwei.
    Yes, your solution was useful, and it is useful for me in case I want to display two fields like ViolationGroupCode and ViolationTypesDescription. But what if I want to display 5 or 6 fields?

    You can see the images in the response below to understand my point specifically.
  • Ali AbdAlNasser Profile Picture
    Ali AbdAlNasser 342 on at
    How to Create a Dropdown with ReferenceGroup to Display Specific Data Only
    Hello @Waed Ayyad 
    As you can see in the pictures below, I applied the steps you mentioned, but the result is that only ViolationGroupCode appears.

    As shown, only the ViolationGroupCode is displayed, and this is not really what I want; I want something like this:
  • Layan Jwei Profile Picture
    Layan Jwei 7,679 Super User 2025 Season 1 on at
    How to Create a Dropdown with ReferenceGroup to Display Specific Data Only
    If my last reply still didn't answer your question.
    Then please share screenshots with everything you did and show us the result of the lookup in the form and explain to us exactly what is not working or what you need help with.
     
    But i think your question is already solved so now i'm confused.
  • Layan Jwei Profile Picture
    Layan Jwei 7,679 Super User 2025 Season 1 on at
    How to Create a Dropdown with ReferenceGroup to Display Specific Data Only
    Hi Ali,
     
    Sorry but I don't understand what you are stuck at exactly, can you please explain further?
     
    What are you trying to achieve?
     
    You want the lookup result to return GroupCode and Description right? But when you choose a value from the lookup, you want only GroupCode to appear in blue right?
     
    If that's the case I told you what needs to be done already and you said it works.
     
    The result in blue is controlled by the replacement field group property you set in the form control whether it's auto identification or a new field group (you decide) 
    If your unique index is GroupCode alone then use the autoidentification field group
    If you have more than one field in your unique index then create a new field group with GroupCode alone and use it in form control replacement field group property 
     
    And the lookup result is controlled by title field1 and title field2 OR if you fill the autoLookup field group property with fields OR if you have x++ code to override the lookup then the fields returned in code will affect the lookup.
    Choose one of those three options to control the lookup 

  • Ali AbdAlNasser Profile Picture
    Ali AbdAlNasser 342 on at
    How to Create a Dropdown with ReferenceGroup to Display Specific Data Only

    Hello @Layan Jwei,

    I have already read your response to my question, but I keep finding myself stuck at the same point I started from. Either I end up with a ReferenceGroup containing only ViolationGroupCode, or I get a ReferenceGroup containing both ViolationGroupCode and ViolationTypesDescription. However, in this case, both fields are displayed in the cell, unlike the way it works with Title1 and Title2.

  • Waed Ayyad Profile Picture
    Waed Ayyad 7,257 Super User 2025 Season 1 on at
    How to Create a Dropdown with ReferenceGroup to Display Specific Data Only
     
    Regarding to your inquiry here, I mean you removed the Description field from the unique index, and this removes the first issue for you to have (Code and Description) in your control.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,162 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,962 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans