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, ...
Answered

How to get a lookup on form column with reference to the aother column on the form.

(0) ShareShare
ReportReport
Posted on by 518

Hi All,

How to get a lookup on form column with reference to the aother column on the form.

This code I have written on the column on which we have to get lookup of values which is selected in first column.

public void lookup(FormControl _formControl, str _filterStr)
{
    Query                   query = new Query();
    QueryBuildDataSource    queryBuildDataSource;
    QueryBuildRange         queryBuildRange;
    QueryBuildRange         queryBuildRange1;
    SysTableLookup          sysTableLookup;
    QueryBuildFieldList     QueryBuildFieldList;
    Esp_Modules             modules;
    ;
    //Create an instance of SysTableLookup with the form control passed in
    sysTableLookup = SysTableLookup::newParameters(tablenum(Esp_Modules), _formControl);
    //Add the fields to be shown in the lookup form
    sysTableLookup.addLookupfield(fieldnum(Esp_Modules, ModuleId));
    sysTableLookup.addLookupfield(fieldnum(Esp_Modules, Name));
    sysTableLookup.addLookupfield(fieldnum(Esp_Modules, CertificationId));
   // sysTableLookup.addLookupfield(fieldnum(Esp_Modules, Name));
    //create the query datasource
    queryBuildDataSource = query.addDataSource(tablenum(Esp_Modules));
    //Only show LocalEndpoints for the current company
    queryBuildRange = queryBuildDataSource.addRange(fieldnum(Esp_Modules, ModuleId));

 

    while select ModuleId from modules where modules.CertificationId == Esp_Certifications_Module.CertificationId
    //SalaryAmend.GridId is the FormTable.Fild1
    //queryBuildRange.(modules.ModuleId);
    queryBuildRange.value(modules.ModuleId);
    //this select query makes the queryBuildRange values from another table for the datasource of another table
    //Assign the query to the lookup form
    sysTableLookup.parmQuery(query);
    // Perform lookup
    sysTableLookup.performFormLookup();
    // Don't call super()
    //super()
}

Column CertificationName is selected then CertificationId will populate automatically which is working fine , but the Module Id is not populating according to CertificationId.

How to get this ModuleId field Lookup related to CertificationId?

Thanks and regards

Siddhant Singh

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    239,152 Most Valuable Professional on at

    You have a while select setting a value of a range:

    while select ModuleId from modules
    	where modules.CertificationId == Esp_Certifications_Module.CertificationId
    {
    	queryBuildRange.value(modules.ModuleId);
    }

    I guess you assume that it'll add a range for each ModuleId, but that's note the case. You're not creating multiple ranges; you're changing a value of the same range. Effectively you add a range for the last ModuleId only.

    The fix is simple - create new ranges inside the loop:

    while select ModuleId from modules
    	where modules.CertificationId == Esp_Certifications_Module.CertificationId
    {
        queryBuildRange = queryBuildDataSource.addRange(fieldnum(Esp_Modules, ModuleId));
    	queryBuildRange.value(modules.ModuleId);
    }

  • Martin Dráb Profile Picture
    239,152 Most Valuable Professional on at

    Nevertheless I wonder why you don't simply filter Esp_Modules by CertificationId.

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 681

#2
André Arnaud de Calavon Profile Picture

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

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 218 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans