web
You’re offline. This is a read only version of the page.
close
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

lookup filter not working in d365 form.

(0) ShareShare
ReportReport
Posted on by 1,836

I have created two fields in which if i select country the state should get filter according to that country , so if i select country of final  destination as  "ITA" then the port of loding only show the value of port from italy , but its showing value from all countries , how can apply filter from this , my code is below.

pastedimage1676459669424v1.png

pastedimage1676459700358v2.png

 [FormControlEventHandler(formControlStr(SalesTable, SalesOrderExim_PortOfLoading), FormControlEventType::Lookup)]
    public static void SalesOrderExim_PortOfLoading_OnLookup(FormControl sender, FormControlEventArgs e)
    {
        Query                   query;
        SysTableLookup          sysTableLookup;
        QueryBuildDataSource    queryBuildDataSource;

        query = new Query();
        sysTableLookup = SysTableLookup::newParameters(tableNum(dev_PortTbl), sender);
        queryBuildDataSource qbdsdev_PortTbl = query.addDataSource(tableNum(dev_PortTbl));
        sysTableLookup.addLookupfield(fieldNum(dev_PortTbl,Port));
      

        sysTableLookup.parmQuery(query);
        sysTableLookup.performFormLookup();

    }

I have the same question (0)
  • GirishS Profile Picture
    27,827 Moderator on at

    Hi Dinesh,

    Where did you the add range to dev_PortTbl which has Port value?

    You need to add Country as a range to dev_PortTbl.

    Thanks,

    Girish S.

  • Suggested answer
    Mohit Rampal Profile Picture
    12,565 Moderator on at

    Hi, you have not added range in the code.

    Check this article and add range of value selected in Country field

    community.dynamics.com/.../applying-range-on-the-lookup-based-on-the-selection-of-value-on-other-field-x

  • Dineshkarlekar Profile Picture
    1,836 on at

    this is lookup code for " country of final distination"

    [FormControlEventHandler(formControlStr(SalesTable, SalesOrderExim_CountryOfFinalDestination), FormControlEventType::Lookup)]
        public static void SalesOrderExim_CountryOfFinalDestination_OnLookup(FormControl sender, FormControlEventArgs e)
        {
            Query                   query;
            SysTableLookup          sysTableLookup;
            QueryBuildDataSource    queryBuildDataSourceView;
    
            query = new Query();
            sysTableLookup = SysTableLookup::newParameters(tableNum(LogisticsAddressCountryRegionNameView), sender);
            queryBuildDataSourceView = query.addDataSource(tableNum(LogisticsAddressCountryRegionNameView));
            queryBuildDataSourceView.addRange(fieldNum(LogisticsAddressCountryRegionNameView, LanguageId)).value(queryValue(currentUserLanguage()));
    
            sysTableLookup.addLookupfield(fieldNum(LogisticsAddressCountryRegionNameView, CountryRegionId));
            sysTableLookup.addLookupfield(fieldNum(LogisticsAddressCountryRegionNameView, ShortName));
            sysTableLookup.setLabel("@SYS7576");
    
            sysTableLookup.parmQuery(query);
            sysTableLookup.performFormLookup();
        }
    

    her is code with range 

     [FormControlEventHandler(formControlStr(SalesTable, SalesOrderExim_PortOfLoading), FormControlEventType::Lookup)]
        public static void SalesOrderExim_PortOfLoading_OnLookup(FormControl sender, FormControlEventArgs e)
        {
            FormRun                 element;
            FormControl             formCtrl;
            Query                   query;
            SysTableLookup          sysTableLookup;
            QueryBuildDataSource    queryBuildDataSource;
    
            element  = sender.formRun();
            formCtrl = element.design().controlName(formControlStr(SalesTable,SalesOrderExim_CountryOfFinalDestination));
    
            query = new Query();
            sysTableLookup = SysTableLookup::newParameters(tableNum(dev_PortTbl), sender);
            queryBuildDataSource qbdsdev_PortTbl = query.addDataSource(tableNum(dev_PortTbl));
            sysTableLookup.addLookupfield(fieldNum(dev_PortTbl,Port));
    
            qbdsdev_PortTbl.addRange(fieldNum(LogisticsAddressCountryRegionNameView, CountryRegionId)).value(formCtrl.valueStr());
           
    
            sysTableLookup.parmQuery(query);
            sysTableLookup.performFormLookup();
    
        }

  • Verified answer
    GirishS Profile Picture
    27,827 Moderator on at

    Code seems to be wrong. You need to add range to the table field if the table is present in the query.

    You added LogisticsAddressCountryRegionNameView which is not added as datasource in your query.

    Does dev_PortTbl has CountryRegionId field?

    Thanks,

    Girish S.

  • Dineshkarlekar Profile Picture
    1,836 on at

    hi

    thanks for the link it was really helping.

    hi  

    thanks for correction now code is working as i need .

    pastedimage1676465717392v1.png

    pastedimage1676465734491v2.png

     [FormControlEventHandler(formControlStr(SalesTable, SalesOrderExim_PortOfLoading), FormControlEventType::Lookup)]
        public static void SalesOrderExim_PortOfLoading_OnLookup(FormControl sender, FormControlEventArgs e)
        {
            FormRun                 element;
            FormControl             formCtrl;
            Query                   query;
            SysTableLookup          sysTableLookup;
            QueryBuildDataSource    queryBuildDataSource;
    
            element  = sender.formRun();
            formCtrl = element.design().controlName(formControlStr(SalesTable,SalesOrderExim_CountryOfFinalDestination));
    
            query = new Query();
            sysTableLookup = SysTableLookup::newParameters(tableNum(dev_PortTbl), sender);
            queryBuildDataSource qbdsdev_PortTbl = query.addDataSource(tableNum(dev_PortTbl));
            sysTableLookup.addLookupfield(fieldNum(dev_PortTbl,Port));
    
            qbdsdev_PortTbl.addRange(fieldNum(dev_PortTbl,Country )).value(formCtrl.valueStr());
           
    
            sysTableLookup.parmQuery(query);
            sysTableLookup.performFormLookup();
    
        }

    thanks, 

    regards ,

    Dinesh.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

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

#1
Martin Dráb Profile Picture

Martin Dráb 611 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 529 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans