Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

Display the lookup based on another lookup value

(0) ShareShare
ReportReport
Posted on by

Hi  team,

I have 3 lookup fields Asset Group, Asset Type and Asset category.

I need to display the lookup based on another lookup value in D365FO.

for example - 

If I select Asset group AG001 from lookup then it should display the lookup in Asset type and Asset Category which is associated with AG001 only. NOT all the values.

If I select Asset Type AT005 from lookup,  then it should display the lookup in Asset Group and Asset Category which is associated with AT001 only. NOT all the values.

If i select  Asset Category AC009 from lookupthen it should display the lookup in Asset Group and Asset Type  which is associated with AC001 only. NOT all the values.

Kindly let me know how to acheive this?

Please give me more shed on this.

thanks!

  • Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,587 Super User 2024 Season 1 on at
    RE: Display the lookup based on another lookup value

    /*Asset Category*/
        [FormControlEventHandler(formControlStr(EntAssetObjectTableCreate, ObjectTable_HSAssetCategory), FormControlEventType::Lookup)]
        public static void ObjectTable_HSAssetCategory_OnLookup(FormControl sender, FormControlEventArgs e)
        {
            
            FormRun                   element;
            FormControl               formCtrl;
            Query                     query;
            QueryBuildDataSource      qbdsEntAssetObjectTable;//, hsAssetGroup;
            SysTableLookup            sysTableLookup;
    
            element = sender.formRun();
            formCtrl = element.design().controlName(formControlStr(EntAssetObjectTableCreate,  ObjectTable_HSAssetCategory));
    
            sysTableLookup = SysTableLookup::newParameters(tableNum(EntAssetObjectTable), sender);
            query = new Query();
            qbdsEntAssetObjectTable = query.addDataSource(tableNum(EntAssetObjectTable));
    
            sysTableLookup.addLookupfield(fieldNum(EntAssetObjectTable, AssetGroup));
            qbdsEntAssetObjectTable.addRange(fieldNum(EntAssetObjectTable, AssetCategory)).value(formCtrl.valueStr());
    
            sysTableLookup.parmQuery(query);
            sysTableLookup.performFormLookup();        
    
        }

    Use this code. I have see that some other table also used. Is that also a table? if yes you have to give the table link in query.

  • @rp@n Profile Picture
    @rp@n on at
    RE: need to display the lookup based on another lookup value in D365FO.

    Hi Bharani,

    /*Asset Category*/
        [FormControlEventHandler(formControlStr(EntAssetObjectTableCreate, ObjectTable_HSAssetCategory), FormControlEventType::Lookup)]
        public static void ObjectTable_HSAssetCategory_OnLookup(FormControl sender, FormControlEventArgs e)
        {
            
            FormRun                   element;
            FormControl               formCtrl;
            Query                     query;
            QueryBuildDataSource      EntAssetObjectTableCreate;//, hsAssetGroup;
            SysTableLookup            sysTableLookup;
    
            element = sender.formRun();
            formCtrl = element.design().controlName(formControlStr(EntAssetObjectTableCreate,  ObjectTable_HSAssetCategory));
    
            sysTableLookup = SysTableLookup::newParameters(tableNum(HSAssetgroup), sender);
            query = new Query();
            EntAssetObjectTableCreate = query.addDataSource(
            EntAssetObjectTableCreate = query.addDataSource(tableNum(HSAssetgroup));
    
            sysTableLookup.addLookupfield(fieldNum(HSAssetgroup, AssetGroup));
            EntAssetObjectTableCreate.addRange(fieldNum(HSAssetgroup, AssetCategory)).value(formCtrl.valueStr());
    
            sysTableLookup.parmQuery(query);
            sysTableLookup.performFormLookup();        
    
        }

    Below I will give ypu the table name

    the form is - EntAssetObjectTableCreate

    form- data source - EntAssetObjectTbale

    Asset category - HSAsetCategory

    Pls give me more sked on this. thanks!

    Asset group - HSAssetGroup

  • Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,587 Super User 2024 Season 1 on at
    RE: need to display the lookup based on another lookup value in D365FO.

    Can you send your code? Because I don't know your table names exactly.

  • @rp@n Profile Picture
    @rp@n on at
    RE: need to display the lookup based on another lookup value in D365FO.

    Hi Bharani,

    Kindly send me the code pls, what you explain to change.

    I have done that but same result

  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,587 Super User 2024 Season 1 on at
    RE: need to display the lookup based on another lookup value in D365FO.

    Line 24: Change the name of the table buffer to table name in tableNum method.

    Same in 26 you have added the buffer in tablenum method. It should be table name.

    Like QueryBuildDataSource qbdsTableName; one buffer is enough.

    In 24 you will add the original table name beside sender.

    In 26 you have to give like qbdsTableName = query.addDataSource(tableNum(TableName));

    And similarly change accordingly in 28 and 29. Then do build and sync and check.

    Do exactly as the links provided.

  • @rp@n Profile Picture
    @rp@n on at
    RE: need to display the lookup based on another lookup value in D365FO.

    Hi All, 

    Asset Category lookup is showing below values.

    Suppose I select the value AS002 from Asset Category

    0486.a1.jpg

    Then I am looking for Asset Group lookup only those values which is only related to AS002 but it showing all the values as below

    8473.a2.jpg

    But I am looking for the value only OFFICE from the Asset Category lookup

    3107.a3.jpg

    To achieve this, I wrote below code but it is not working. Kindly let me know where is wrong?

    class HSAssetObjectTableCreate
    {   
    
        /// 
        ///
        /// 
        /// 
        ///     
       
        /*Asset Category*/
        [FormControlEventHandler(formControlStr(EntAssetObjectTableCreate, ObjectTable_HSAssetCategory), FormControlEventType::Lookup)]
        public static void ObjectTable_HSAssetCategory_OnLookup(FormControl sender, FormControlEventArgs e)
        {
            
            FormRun                   element;
            FormControl               formCtrl;
            Query                     query;
            QueryBuildDataSource      EntAssetObjectTableCreate, hsAssetGroup;
            SysTableLookup            sysTableLookup;
    
            element = sender.formRun();
            formCtrl = element.design().controlName(formControlStr(EntAssetObjectTableCreate,  ObjectTable_HSAssetCategory));
    
            sysTableLookup = SysTableLookup::newParameters(tableNum(hsAssetGroup), sender);
            query = new Query();
            EntAssetObjectTableCreate = query.addDataSource(tableNum(hsAssetGroup));
    
            sysTableLookup.addLookupfield(fieldNum(hsAssetGroup, AssetGroup));
            EntAssetObjectTableCreate.addRange(fieldNum(hsAssetGroup, AssetCategory)).value(formCtrl.valueStr());
    
            sysTableLookup.parmQuery(query);
            sysTableLookup.performFormLookup();        
    
        }
    }

    Pls give me more shed on this.

    thanks!

  • @rp@n Profile Picture
    @rp@n on at
    RE: need to display the lookup based on another lookup value in D365FO.

    Hi Baharani,

    What cancelsupercall does ?

    When it is actual required to call ?

    Pls. give me more shed on this.

    thanks!

  • @rp@n Profile Picture
    @rp@n on at
    RE: need to display the lookup based on another lookup value in D365FO.

    Thanks Baharani, I will update you

  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,587 Super User 2024 Season 1 on at
    RE: need to display the lookup based on another lookup value in D365FO.

    Presently I donot have a laptop or vm.

    Use the below code which is in the method which actually helps your requirement.

    Also give a condition for range if that field value exists only then add this range. As said earlier it is not required to call cancelsupercall.

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

  • @rp@n Profile Picture
    @rp@n on at
    RE: need to display the lookup based on another lookup value in D365FO.

    Yes, you mean to say I need to write syslookup for all 3 event handlers ?

    Kindly send me the sample code pls

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,074 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,900 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans