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, ...
Unanswered

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

(0) ShareShare
ReportReport
Posted on by 1,552

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

I have the same question (0)
  • Mohit Rampal Profile Picture
    12,565 Moderator on at

    Hi, I have answered in the below related thread

    community.dynamics.com/.../1342340

  • junior AX Profile Picture
    1,552 on at

    Hi Mohit,

    1. The link doesn't show that i can override the lookup method or not? Can we?

    2. The standard case category lookup doesn't contain such code ..it just worked with relations...how?

    3. Can i do it as a control that is not bound to a datasource? Or do i need to create a new field in caseDetailBase? As i don't want to use the standard field in caseDetail base

  • Mohit Rampal Profile Picture
    12,565 Moderator on at

    You need to create 'Tree' control same as mentioned in the articles as well in the standard system. And override expanding and selectionChanged method as well.

    However, there is no lookup method in the Tree control, so best to create a new Form (Lookup Form) as specified in the article and in add the range in init and executeQuery method to display certain data. In this case you need to pass ParentRecId from your form to this lookup form.

  • junior AX Profile Picture
    1,552 on at

    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?

  • junior AX Profile Picture
    1,552 on at

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

  • Mohit Rampal Profile Picture
    12,565 Moderator on at

    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
    1,552 on at

    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 

  • junior AX Profile Picture
    1,552 on at

    Any idea Anyone?

  • Mohit Rampal Profile Picture
    12,565 Moderator on at

    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
    1,552 on at

    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

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

#2
André Arnaud de Calavon Profile Picture

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

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 408 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans