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, ...
Suggested Answer

Display the lookup based on another lookup value

(0) ShareShare
ReportReport
Posted on by 30

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!

I have the same question (0)
  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at

    So if I understand correctly requirement is what ever field mentioned above is filled with some value then the other fields should show the lookup based / related to first field right?

    This can be done as below.

    First you have to give the relations for each of these fields at table level in such a way that it should be as follows.

    MyTable.AssetGroup == RelatedTable.AssetGroup

    MyTable.AssetId == Related table.AssetId

    MyTable.AssetCategory == RelatedTable.AssetCategory

    Now write lookup methods at form at those controls so that in the query write the condition like

    If(myTable.AssetGroup)

    //Add range with that value in your lookup query

    Similarly you can add other ranges.

  • @rp@n Profile Picture
    30 on at

    Thanks Baharani for the response.

    I have done already all relations...

    class HSAssetObjectTableCreate
    {
        /// 
        ///
        /// 
        /// 
        ///     
       
        /*Asset Category*/
        [FormControlEventHandler(formControlStr(EntAssetObjectTableCreate, ObjectTable_HSAssetCategory), FormControlEventType::Lookup)]
        public static void ObjectTable_HSAssetCategory_OnLookup(FormControl sender, FormControlEventArgs e)
        {
            // to do
        } 
      
        /// 
        ///
        /// 
        /// 
        /// 
       
        /*Asset group*/
        [FormControlEventHandler(formControlStr(EntAssetObjectTableCreate, ObjectTable_HSAssetGroup), FormControlEventType::Lookup)]
        public static void ObjectTable_HSAssetGroup_OnLookup(FormControl sender, FormControlEventArgs e)
        {
            // to do
        }
        
        /// 
        ///
        /// 
        /// 
        /// 
       
        /*Aset type*/
        [FormControlEventHandler(formControlStr(EntAssetObjectTableCreate, Object_ObjectType), FormControlEventType::Lookup)]
        public static void Object_ObjectType_OnLookup(FormControl sender, FormControlEventArgs e)
        {
            // to do
        }
    
    }

    As suggested by you, is it right to perform the range above the code?

    Kindly show me the code pls

    pls give me more shed on this

  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at

    Refer to this url where the exact thing is done. But you are not required to cancel super call as you are not overriding any standard or already present lookup.

    dynamics365musings.com/.../

    Another thing you need to change is as said earlier you have to add the condition like this field has some value then add the range and query should execute with that range. Else all the lookup without the range would execute.

  • @rp@n Profile Picture
    30 on at

    Thanks, 

    Sure I will go through the link.

    Kindly confirm, is my code is correct?

  • Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at

    Your code seems fine. I don't know the exact control name in that form. But if you have copied the lookup event of that exact control and pasted it here in the class, then that would be correct code.

  • @rp@n Profile Picture
    30 on at

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

    Kindly send me the sample code pls

  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at

    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
    30 on at

    Thanks Baharani, I will update you

  • @rp@n Profile Picture
    30 on at

    Hi Baharani,

    What cancelsupercall does ?

    When it is actual required to call ?

    Pls. give me more shed on this.

    thanks!

  • @rp@n Profile Picture
    30 on at

    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!

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 659 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 289 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans