Skip to main content

Notifications

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

Adding dynamic field controls in the form

(1) ShareShare
ReportReport
Posted on by 300
Hello All,
 
I am trying to add dynamic controls in the form. I have added a tabPage, a group and added field controls in the group.
 
The form is working fine, but the tab page is collapsed while opening the form. I tried to use tabPage.FastTabExpanded(FastTabExpanded::Always), the tab is expanded but the controls are not visible. If I set tabPage.FastTabExpanded(FastTabExpanded::Yes) fields are visible but tabpage is collapsed and have to extend them manually.
 
Adding the code for reference,
 
private FormGroupControl buildTabPageControl(){    FormGroupControl            groupControl;    FormTabPageControl          tabPageControl;    tabPageControl = callerTabControl.addControl(FormControlType::TabPage, 'TestTabPage' + enum2Str(FormControlType::TabPage),        callerInsertAfterControl ? callerInsertAfterControl : callerTabControl.controlNum(callerTabControl.controlCount()));    tabPageControl.caption('Test'');    if (callerTabControl.style() == TabStyle::FastTabs)    {        tabPageControl.fastTabExpanded(FastTabExpanded::Always);    }    groupControl = tabPageControl.addControl(FormControlType::Group, 'TestGroup'' + /@SYS80404/);    groupControl.arrangeMethod(FormArrangeMethod::HorizontalWrap);    return groupControl;}
 
Any insights or suggestions on what I might be missing or causing this behavior?
  • Wekey Profile Picture
    Wekey 300 on at
    Adding dynamic field controls in the form
    Original code as it was not readable in the post
    private FormGroupControl buildTabPageControl()
    {   
        FormGroupControl            groupControl;
        FormTabPageControl          tabPageControl;
    
        tabPageControl = callerTabControl.addControl(FormControlType::TabPage, 'Test' + enum2Str(FormControlType::TabPage),
            callerInsertAfterControl ? callerInsertAfterControl : callerTabControl.controlNum(callerTabControl.controlCount()));
        tabPageControl.caption("Test TabPage");
    
        if (callerTabControl.style() == TabStyle::FastTabs)
        {
      	tabPageControl.fastTabExpanded(FastTabExpanded::Always);
        }
        groupControl = tabPageControl.addControl(FormControlType::Group, 'Test' + "@SYS80404");
        groupControl.arrangeMethod(FormArrangeMethod::HorizontalWrap);
    
        return groupControl;
    }
    Also I tried to get the tabPageControl and do the same tabPageControl.fastTabExpanded(FastTabExpanded::Always); after adding the fields to the group, still no luck with that it behaves the same. If I set the FastTabExpanded::Yes (Anything expect Always)  I can able to see the field but the tabpage is collapsed. When I set to Always the tabPage is expanded but couldn't able to see the fields.
  • Wekey Profile Picture
    Wekey 300 on at
    Adding dynamic field controls in the form
    Hello Andre and Layan,
     
    Thanks for the reply. I tried to add the code snippet I am not sure why the code looks that way. However adding the remaining code here
    private FormGroupControl getFormGroupControl()
    {
        FormGroupControl groupControl;
    
        groupControl = this.buildTabPageControl();        
    
        return groupControl;
    }
    
    void updateDesign(boolean _isDynamicControl = false)
    {
        Map                 fieldsAdded;
        FormGroupControl    formGroupControl;        
    
        formGroupControl    = this.getFormGroupControl();
        fieldsAdded         = this.getAvailableField();
    
        if (_isDynamicControl)
        {
            this.addDynamicFieldsControl(formGroupControl, fieldsAdded);
        }
        else
        {
            
            this.addFieldsControl(formGroupControl, fieldsAdded);
        }
    }
    private void addDynamicFieldsControl(FormGroupControl _formGroupControl, Map _fieldsAdded)
    {
        MapEnumerator   fieldsEnumerator = _fieldsAdded.getEnumerator();
    
        _formGroupControl.columns(_fieldsAdded.elements() ? _fieldsAdded.elements() : 1);
    
        while (fieldsEnumerator.moveNext())
        {
            str fieldType = Table::getFieldType(fieldsEnumerator.currentKey());
    
            switch (fieldType)
            {
                case enum2Str(FieldType::String):
                    FormStringControl stringControl = _formGroupControl.addControl(FormControlType::String, fieldId2Name(tableNum(Table), fieldsEnumerator.currentKey()));
                    stringControl.label(fieldsEnumerator.currentValue());
                    stringControl.text(formDataSource.cursor().(fieldsEnumerator.currentKey()));
                    stringControl.lookupButton(Table::exist(fieldsEnumerator.currentValue()) ? FormLookupButton::Always : FormLookupButton::Never);
                    stringControl.registerOverrideMethod(methodStr(FormStringControl, lookup), methodStr(TestFormHelper, dynamicCtrlLookup), this);
                    stringControl.registerOverrideMethod(methodStr(FormStringControl, modified), methodStr(TestFormHelper, dynamicCtrlModified), this);
                    stringControl.cacheDataMethod(NoYes::Yes);
                    break;
    
                case enum2Str(FieldType::Integer):
                    FormIntControl intControl = _formGroupControl.addControl(FormControlType::Integer, fieldId2Name(tableNum(Table), fieldsEnumerator.currentKey()));
                    intControl.label(fieldsEnumerator.currentValue());
                    intControl.value(formDataSource.cursor().(fieldsEnumerator.currentKey()));
                    break;
    
                case enum2Str(FieldType::Real):
                    FormRealControl realControl = _formGroupControl.addControl(FormControlType::Real, fieldId2Name(tableNum(Table), fieldsEnumerator.currentKey()));
                    realControl.label(fieldsEnumerator.currentValue());
                    realControl.realValue(formDataSource.cursor().(fieldsEnumerator.currentKey()));
                    break;
    
                case enum2Str(FieldType::Date):
                    FormDateControl dateControl = _formGroupControl.addControl(FormControlType::Date, fieldId2Name(tableNum(Table), fieldsEnumerator.currentKey()));
                    dateControl.label(fieldsEnumerator.currentValue());
                    dateControl.dateValue(formDataSource.cursor().(fieldsEnumerator.currentKey()));
                    break;
    
                case enum2Str(FieldType::DateTime):
                    FormDateTimeControl dateTimeControl = _formGroupControl.addControl(FormControlType::DateTime, fieldId2Name(tableNum(Table), fieldsEnumerator.currentKey()));
                    dateTimeControl.label(fieldsEnumerator.currentValue());
                    dateTimeControl.dateTimeValue(formDataSource.cursor().(fieldsEnumerator.currentKey()));
                    break;
    
                case enum2Str(FieldType::Checkbox):
                    FormComboBoxControl comboBoxControl = _formGroupControl.addControl(FormControlType::ComboBox, fieldId2Name(tableNum(Table), fieldsEnumerator.currentKey()));
                    comboBoxControl.label(fieldsEnumerator.currentValue());
                    comboBoxControl.enumType(enumNum(TestEnum));
                    comboBoxControl.selection(formDataSource.cursor().(fieldsEnumerator.currentKey()));
                    break;
    
                default:
                    //do nothing
                    break;
            }
        }
    }
    private FormGroupControl buildTabPageControl()
    {   
        FormGroupControl            groupControl;
        FormTabPageControl          tabPageControl;
    
        tabPageControl = callerTabControl.addControl(FormControlType::TabPage, 'Test' + enum2Str(FormControlType::TabPage),
            callerInsertAfterControl ? callerInsertAfterControl : callerTabControl.controlNum(callerTabControl.controlCount()));
        tabPageControl.caption("TestTabPage");
    
        groupControl = tabPageControl.addControl(FormControlType::Group, 'Test' + "@SYS80404");
        groupControl.arrangeMethod(FormArrangeMethod::HorizontalWrap);
    
        return groupControl;
    }
     
  • André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,965 Super User 2025 Season 1 on at
    Adding dynamic field controls in the form
    Hi Wekey,
     
    When I quickly scan your coding, I don't see fields being added. Can you share the full method in a new reply, please?
  • Layan Jwei Profile Picture
    Layan Jwei 7,613 Super User 2025 Season 1 on at
    Adding dynamic field controls in the form
    Hi WeKey,
     
    Can you please share ur code again in the comments section, because it's not readable.
     
    Are you saying in case u set it as always, none of the fields appear? Did u try to clear usage data?
     
    Here's more info about the fastTab expanded property
     

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…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,965 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,817 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans