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 506

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
    Martin Dráb 231,403 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
    Martin Dráb 231,403 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

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…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 231,403 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans