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

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

  • Martin Dráb Profile Picture
    233,029 Most Valuable Professional on at
    RE: How to get a lookup on form column with reference to the aother column on the form.

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

  • Verified answer
    Martin Dráb Profile Picture
    233,029 Most Valuable Professional on at
    RE: How to get a lookup on form column with reference to the aother column on the form.

    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);
    }

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,351 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 233,029 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans