SysTableBrowser extension to control visible fields and pre-applied ranges

Often, due to a large number of fields in the table or an enormous amount of records, the standard SysTableBrowser is heavily lagging, especially on the DEV boxes.
Also, when you are interested in only several field contents, it is not convenient to scroll back and forth to investigate particular field values.
Here is the SysTableBrowser extension, which you can use together with the Table Browser tool.
It allows you to:
- indicate fields which you want to see.
- predefine field ranges to see only specific records





How to install?
- create a class with the name DXTSysTableBrowserFrm_Extension
- copy/paste the following content
- compile

/// <summary>
/// CoC extension of SysTableBrowser form
/// </summary>
[ExtensionOf(formStr(SysTableBrowser))]
final class DXTSysTableBrowserFrm_Extension
{
    private Map                 visibleFieldList;
    private boolean             showOnlyFieldList;
    private TableId             tableId;
    private FormGridControl     formGridControlAllFields;
    private FormGroupControl    customGroup;
    private str                 parmFieldList;
    private str                 parmRangeList;
    private FormStringControl   visibleFieldListControl;
    private FormStringControl   rangeFieldListControl;

    /// <summary>
    /// CoC for init method
    /// </summary>
    public void init()
    { 
        next init();

        parmFieldList               = strLRTrim(getClientURLQueryValue('FieldList'));
        parmRangeList               = strLRTrim(getClientURLQueryValue('RangeList'));
        formGridControlAllFields    = this.design(0).controlName(formControlStr(SysTableBrowser, AllFieldsGrid));
        tableId                     = formGridControlAllFields.formRun().dataSource().cursor().TableId;

        this.parseFieldListParam();
        this.applyRanges();
        this.showHideFields();
        this.addControls();
    }

    /// <summary>
    /// Applies datasource ranges.
    /// </summary>
    public void applyRanges()
    {
        FormDataSource          fds = this.dataSource(1);
        Query                   q;
        QueryBuildDataSource    qbds;

        container   ranges = str2con(parmRangeList, ',');
        str         rangeValue;
        FieldName   fieldName;
        FieldId     fieldId;
        int         i;
       
        if (fds)
        {
            q       = fds.query();
            qbds    = q.dataSourceNo(1);
            qbds.clearRanges();

            if (parmRangeList && conLen(ranges))
            {
                for (i = 1; i <= conLen(ranges); i++)
                {
                    str         pairStr = strLTrim(conPeek(ranges, i));
                    container   pairCnt = str2con(pairStr, '=');
                    fieldName   = conPeek(pairCnt, 1);
                    rangeValue  = conPeek(pairCnt, 2);
                    fieldId     = fieldName2Id(tableId, fieldName);
                    if (fieldId && rangeValue)
                    {
                        QueryBuildRange qbr = qbds.addRange(fieldId);
                        qbr.value(rangeValue);
                        if (!visibleFieldList.exists(fieldId))
                        {
                            visibleFieldList.add(fieldId, 1);
                            parmFieldList += ','+fieldName;
                        }
                    }
                }
            }
        }
    }

    /// <summary>
    /// Add additional controls on the SySTableBrowser form.
    /// </summary>
    public void addControls()
    {
        FormGroupControl   filterGroup = this.design().controlName(formControlStr(SysTableBrowser, CustomFilter));
        FormGroupControl   parentGroup;

        if (filterGroup)
        {
            parentGroup = filterGroup.parentControl();

            customGroup = this.design().addControl(FormControlType::Group, 'DXTCustomGroup', filterGroup);
            customGroup.caption('Extended functionality');
            customGroup.columns(2);

            visibleFieldListControl = customGroup.addControl(FormControlType::String, 'DXTVisibleFields');
            visibleFieldListControl.multiLine(true);
            visibleFieldListControl.width(400, -1);
            visibleFieldListControl.displayHeight(2, AutoMode::Fixed);
            visibleFieldListControl.text(parmFieldList);
            visibleFieldListControl.label('Visible fields');
            visibleFieldListControl.helpText('Comma-separated list of visible field names (AOT).');
            visibleFieldListControl.labelPosition(LabelPosition::Left);

            visibleFieldListControl.registerOverrideMethod(
                methodStr(FormStringControl, modified),
                methodStr(DXTSysTableBrowserFrm_Extension, dxtVisibleFieldListControlModified),
                this);

            rangeFieldListControl = customGroup.addControl(FormControlType::String, 'DXTRangeFields');
            rangeFieldListControl.multiLine(true);
            rangeFieldListControl.width(400, -1);
            rangeFieldListControl.displayHeight(2, AutoMode::Fixed);
            rangeFieldListControl.text(parmRangeList);
            rangeFieldListControl.label('Ranges');
            rangeFieldListControl.helpText('Comma-separated list of field ranges in the format FieldName=RangeValue.');
            rangeFieldListControl.labelPosition(LabelPosition::Left);

            rangeFieldListControl.registerOverrideMethod(
                methodStr(FormStringControl, modified),
                methodStr(DXTSysTableBrowserFrm_Extension, dxtRangeFieldListControlModified),
                this);
        }
    }

    /// <summary>
    /// DXTVisibleFields modified method. To update visible fields, when field list is changed.
    /// </summary>
    /// <param name = "_formControl">FormStringControl</param>
    /// <returns>boolean</returns>
    public boolean dxtVisibleFieldListControlModified(FormStringControl _formControl)
    {
        var locFieldList = strLRTrim(visibleFieldListControl.valueStr());
        if (locFieldList != parmFieldList)
        {
            parmFieldList = locFieldList;
            this.parseFieldListParam();
            this.showHideFields();
        }

        return _formControl.modified();
    }

    /// <summary>
    /// DXTRangeFields modified method. To update ranges, when ranges are changed.
    /// </summary>
    /// <param name = "_formControl">FormStringControl</param>
    /// <returns>boolean</returns>
    public boolean dxtRangeFieldListControlModified(FormStringControl _formControl)
    {
        var locFieldList = strLRTrim(rangeFieldListControl.valueStr());
        if (locFieldList != parmRangeList)
        {
            parmRangeList = locFieldList;
            this.applyRanges();
            FormDataSource fds = this.dataSource(1);
            fds.executeQuery();
        }

        return _formControl.modified();
    }

    /// <summary>
    /// Parse visible field list string.
    /// </summary>
    public void parseFieldListParam()
    {
        showOnlyFieldList   = false;
        visibleFieldList    = new Map(Types::Integer, Types::Integer);

        if (parmFieldList)
        {
            container   fieldNames = str2con(parmFieldList, ',');
            FieldName   fieldName;
            FieldId     fieldId;
            int         i;

            for (i = 1; i <= conLen(fieldNames); i++)
            {
                fieldName   = strLTrim(conPeek(fieldNames, i));
                fieldId     = fieldName2Id(tableId, fieldName);
                if (fieldId)
                {
                    showOnlyFieldList = true;
                    if (!visibleFieldList.exists(fieldId))
                    {
                        visibleFieldList.insert(fieldId, 1);
                    }
                }
            }
        }
    }

    /// <summary>
    /// Show/Hide field based on the user preference.
    /// </summary>
    public void showHideFields()
    {
        if (showOnlyFieldList)
        {
            int             fieldCount      = formGridControlAllFields.controlCount(),
                            i;

            for (i = 1; i <= fieldCount; i++)
            {
                FormControl     formControl     = formGridControlAllFields.controlNum(i);
                FieldBinding    fieldBinding    = formControl.fieldBinding();
                FieldId         fieldId         = fieldBinding.fieldId();

                if (!fieldId || !visibleFieldList.exists(fieldId))
                {
                    formControl.visible(false);
                }
                else
                {
                    formControl.visible(true);
                }
            }
        }
    }

}


Support The Author

 If you found value in what I share, I've set up a Buy Me a Coffee page as a way to show your support.

Buy Me a Coffee

Post a Comment


All Comments


No comments. Be the first one to comment on this post.

Search

About

DaxOnline.org is free platform that allows you to quickly store and reuse snippets, notes, articles related to Dynamics 365 FO.

Authors are allowed to set their own "buy me a coffee" link.
Join us.

Blog Tags