Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Unanswered

How to create tree view lookup for a formReferenceGroupControl that is not bound to a datasource

(0) ShareShare
ReportReport
Posted on by 1,550

Hi,

I added a new int64 control (reference group) without filling dataSource, reference field, replacement field group properties on the form and I want it to look as tree view

then in the init method of the form (CaseDetailCreate) i added this line

ACaseCategory.RegisterOverrideMethod(methodStr(FormReferenceGroupControl, lookup), formMethodStr(CaseDetailCreate, AOverrideCaseCategoryLookup));


 public void AOverrideCaseCategoryLookup(FormReferenceGroupControl _formReferenceGroupControl)
    {
        SysReferenceTableLookup sysTableLookup = SysReferenceTableLookup::newParameters(tableNum(CaseCategoryHierarchyDetail), _formReferenceGroupControl);
        sysTableLookup.addLookupfield(fieldNum(CaseCategoryHierarchyDetail, CaseCategory));
        
        Query query = new Query();
        QueryBuildDataSource queryBuildDataSource;
        queryBuildDataSource = query.addDataSource(tableNum(CaseCategoryHierarchyDetail));
        
        CaseCategoryHierarchyDetail caseCategoryHierarchyDetail;
        CaseCategoryType caseCategoryType;

        select firstonly RecId from caseCategoryHierarchyDetail 
            where caseCategoryHierarchyDetail.CaseCategory == Control1.text()
               
        if (caseCategoryHierarchyDetail)
        {
            this.findCaseCategoryChildAndSubChild(caseCategoryHierarchyDetail.ParentRecId, queryBuildDataSource);
        }

        
        sysTableLookup.parmQuery(query);
        sysTableLookup.performFormLookup();
    }
    
    public void findCaseCategoryChildAndSubChild(RefRecId _ParentRefRecId, QueryBuildDataSource _queryBuildDataSource)
    {
        CaseCategoryHierarchyDetail caseCategoryHierarchyDetail;

        while select caseCategoryHierarchyDetail
            where caseCategoryHierarchyDetail.parentRecId == _ParentRefRecId
        {
            _queryBuildDataSource.addRange(fieldNum(CaseCategoryHierarchyDetail,ParentRecId)).value(queryValue(caseCategoryHierarchyDetail.RecId));

            

            this.findCaseCategoryChildAndSubChild(caseCategoryHierarchyDetail.RecId, _queryBuildDataSource);
        }
    }



but the field is not appearing at all on the form, why is that? and what should I do to make a lookup tree for case categories?
I want it the same as the standard caseCategory, but the difference is that this one starts from a certain node and not show all case categories

  • junior AX Profile Picture
    junior AX 1,550 on at
    RE: How to create tree view lookup for a formReferenceGroupControl that is not bound to a datasource

    Hi Mohit,

    I already did that. In the previous thread. Remember you wrote code for me to show me how to get children based on a parent.

    Even now, when i created a new categoryRecId EDT .. it's somhow the same..right? As u saw from previous comments i added a method called setCaseCategory so that i use it in filters to get what's below it.

    Or am i missing something about your suggestion?

    The thing is how can i amend the code of CaseCategoryLookup form in order to return specific nodes(assuming i created a duplicate form and i can change the code as i want)

  • Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: How to create tree view lookup for a formReferenceGroupControl that is not bound to a datasource

    By duplicating patent category field I mean the form control that is storing value 1A, the one you mentioned in other thread

    'let's say I have a form control where it's value is 1A

    I have another control, where I want to amend the lookup to get the following result, which is anything under 1A'

    If you duplicate that parent category control to create new form control which will display values based on category selected in parent category field. Note that I haven't created filter in Tree control, so not sure if there is easy way to do it. 

  • junior AX Profile Picture
    junior AX 1,550 on at
    RE: How to create tree view lookup for a formReferenceGroupControl that is not bound to a datasource

    ??

  • junior AX Profile Picture
    junior AX 1,550 on at
    RE: How to create tree view lookup for a formReferenceGroupControl that is not bound to a datasource

    Hi Mohit,

    Yes there is a value for both caseCategory and CaseCategoryType.

    Do u mean duplicating the caseCategoryRecId(standard reference group) for the parent instead of creating a new EDT? But does it make a difference?

    If yes, i did this and i duplicated the standard form "caseCategoryLookup' that is used for the parent but i didn't know how to amend the range as the code is complex for the tree and where should i add the recursive code

    Reminder: i need to get all children nodes -- not just one level

  • Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: How to create tree view lookup for a formReferenceGroupControl that is not bound to a datasource

    Are you getting value of Case category and case category type in your lookup form?

    Also, I think you have parent category field and you need to create a child category field lookup. How about duplicating the parent category field and adding range on child category field lookup.

  • junior AX Profile Picture
    junior AX 1,550 on at
    RE: How to create tree view lookup for a formReferenceGroupControl that is not bound to a datasource

    Any idea Anyone?

  • junior AX Profile Picture
    junior AX 1,550 on at
    RE: How to create tree view lookup for a formReferenceGroupControl that is not bound to a datasource

    Hi Mohit,

    yes and i got same result, here's what I did  --- can you please tell me what I need to do more to get the required result?

    1. I created this EDT
    pastedimage1684575000533v2.png

    2. I created an extension of "CaseDetailBase" table and added this EDT as a field in it. In addition to a relation similar to the original relation: (this is the table I need to add to right?)
    pastedimage1684575158081v3.png

    3. I added the control to the form "CaseDetailCreate" form via extension
    pastedimage1684576534448v1.png

    4. This is the code for "CaseDetailCreate" Form

    /// 
    /// Extension class for CaseDetailCreate form
    /// 
    [ExtensionOf(formStr(CaseDetailCreate))]
    final class CaseDetailCreateA_Extension
    {
        public void init()
        {
            next init();
            
            
            CaseDetailBase_ACaseCategoryRecId.RegisterOverrideMethod(methodStr(FormReferenceGroupControl, lookup), formMethodStr(CaseDetailCreate, aOverrideCaseCategoryTestLookup));
        }
        
         public void aOverrideCaseCategoryTestLookup(FormReferenceGroupControl _formReferenceGroupControl)
        {
            Args    args = new Args();
            CaseCategoryType caseCategoryType;
            Object  formRun;
            args.name(formStr(ACaseCategoryHierarchyDetailLookup));
            args.caller(_formReferenceGroupControl);
            formRun = classfactory.formRunClass(args);
            formRun.setCaseCategory('Accident');
            formRun.setCategoryType(str2Enum(caseCategoryType,'General'));
            formRun.init();
            _formStringControl.performFormLookup(formRun);
        }
    }

    5. Here's the customized lookup form
    pastedimage1684505580755v1.png

    [Form]
    public class ACaseCategoryHierarchyDetailLookup extends FormRun
    {
        CaseCategory                        caseCateogry;
        CaseCategoryType                    categoryType;
    
        void setCaseCategory(CaseCategory _caseCategory)
        {
            caseCateogry = _caseCategory;
        }
    
        void setCategoryType(CaseCategoryType _categoryType)
        {
            categoryType = _categoryType;
        }
    
    
        [DataSource]
        class CaseCategoryHierarchyDetail
        {
            /// 
            ///
            /// 
            public void init()
            {
                QueryBuildDataSource    queryBuildDataSource;
                CaseCategoryType        caseCategoryType;
     
                super();
    
                queryBuildDataSource = this.query().dataSourceTable(tableNum(CaseCategoryHierarchyDetail));
                
                CaseCategoryHierarchyDetail caseCategoryHierarchyDetailLocal;
                select firstonly caseCategoryHierarchyDetailLocal
                where caseCategoryHierarchyDetailLocal.CaseCategory == caseCateogry
                    && caseCategoryHierarchyDetailLocal.CategoryType == categoryType;
                if (caseCategoryHierarchyDetailLocal)
                {
                    this.findCaseCategoryChildAndSubChild(caseCategoryHierarchyDetailLocal.ParentRecId, queryBuildDataSource);
                }
                
            }
    
            public void findCaseCategoryChildAndSubChild(RefRecId _ParentRefRecId, QueryBuildDataSource _queryBuildDataSource)
            {
                CaseCategoryHierarchyDetail caseCategoryHierarchyDetailLocal;
    
                while select caseCategoryHierarchyDetailLocal
                where caseCategoryHierarchyDetailLocal.parentRecId == _ParentRefRecId
                {
                    _queryBuildDataSource.addRange(fieldNum(CaseCategoryHierarchyDetail,ParentRecId)).value(queryValue(caseCategoryHierarchyDetailLocal.RecId));
    
    
                    this.findCaseCategoryChildAndSubChild(caseCategoryHierarchyDetailLocal.RecId, _queryBuildDataSource);
                }
            }
    
        }
    
    }


    6. the drop down returned nothing

    pastedimage1684576082378v5.png


    Mohit Rampal 

  • Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: How to create tree view lookup for a formReferenceGroupControl that is not bound to a datasource

    Hi, Instead of unbound field, have you tried creating new EDT, adding your custom lookup form as formRef in EDT, creating a table field. Add a bound control just like mentioned in the articles.

  • junior AX Profile Picture
    junior AX 1,550 on at
    RE: How to create tree view lookup for a formReferenceGroupControl that is not bound to a datasource

    can anyone help? I've been trying for hours now with no luck

  • junior AX Profile Picture
    junior AX 1,550 on at
    RE: How to create tree view lookup for a formReferenceGroupControl that is not bound to a datasource

    Hi Mohit,

    I've added a new string control to "CaseDetailCreate" form (not bound to a datasource). And overrided it's lookup like this:

    /// 
    /// Extension class for CaseDetailCreate form
    /// 
    [ExtensionOf(formStr(CaseDetailCreate))]
    final class CaseDetailCreateA_Extension
    {
        public void init()
        {
            next init();
            
            
            ACaseCategoryTest.RegisterOverrideMethod(methodStr(FormStringControl, lookup), formMethodStr(CaseDetailCreate, aOverrideCaseCategoryTestLookup));
        }
        
         public void aOverrideCaseCategoryTestLookup(FormStringControl _formStringControl)
        {
            Args    args = new Args();
            CaseCategoryType caseCategoryType;
            Object  formRun;
            args.name(formStr(ACaseCategoryHierarchyDetailLookup));
            args.caller(_formStringControl);
            formRun = classfactory.formRunClass(args);
            formRun.setCaseCategory('Accident');
            formRun.setCategoryType(str2Enum(caseCategoryType,'General'));
            formRun.init();
            _formStringControl.performFormLookup(formRun);
        }
    }


    And I've created a lookup form

    pastedimage1684505580755v1.png

    [Form]
    public class ACaseCategoryHierarchyDetailLookup extends FormRun
    {
        CaseCategory                        caseCateogry;
        CaseCategoryType                    categoryType;
    
        void setCaseCategory(CaseCategory _caseCategory)
        {
            caseCateogry = _caseCategory;
        }
    
        void setCategoryType(CaseCategoryType _categoryType)
        {
            categoryType = _categoryType;
        }
    
    
        [DataSource]
        class CaseCategoryHierarchyDetail
        {
            /// 
            ///
            /// 
            public void init()
            {
                QueryBuildDataSource    queryBuildDataSource;
                CaseCategoryType        caseCategoryType;
     
                super();
    
                queryBuildDataSource = this.query().dataSourceTable(tableNum(CaseCategoryHierarchyDetail));
                
                CaseCategoryHierarchyDetail caseCategoryHierarchyDetailLocal;
                select firstonly caseCategoryHierarchyDetailLocal
                where caseCategoryHierarchyDetailLocal.CaseCategory == caseCateogry
                    && caseCategoryHierarchyDetailLocal.CategoryType == categoryType;
                if (caseCategoryHierarchyDetailLocal)
                {
                    this.findCaseCategoryChildAndSubChild(caseCategoryHierarchyDetailLocal.ParentRecId, queryBuildDataSource);
                }
                
            }
    
            public void findCaseCategoryChildAndSubChild(RefRecId _ParentRefRecId, QueryBuildDataSource _queryBuildDataSource)
            {
                CaseCategoryHierarchyDetail caseCategoryHierarchyDetailLocal;
    
                while select caseCategoryHierarchyDetailLocal
                where caseCategoryHierarchyDetailLocal.parentRecId == _ParentRefRecId
                {
                    _queryBuildDataSource.addRange(fieldNum(CaseCategoryHierarchyDetail,ParentRecId)).value(queryValue(caseCategoryHierarchyDetailLocal.RecId));
    
    
                    this.findCaseCategoryChildAndSubChild(caseCategoryHierarchyDetailLocal.RecId, _queryBuildDataSource);
                }
            }
    
        }
    
    }


    but the lookup is not returning anything

    pastedimage1684505630415v2.png

    Mohit Rampal  can you please help?

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,962 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans