Home > DynamicsAx Utilities > Form browser for Dynamics Ax-Tables

Form browser for Dynamics Ax-Tables


In this example I am going to illustrate, a Form will be displayed, from the Table’s Context Menu. The form will show the records from selected table. We can call this form as Form Browser for tables.

I had created the following Class for displaying the Form browser from AOT-Tables.

class PSShowFormForTable

{

}

 

void createForm(TableId     mytableId)

{

        #AOT

        Args                    args;

        FormBuildDesign         formBuildDesign;

        Form                    form;

        Formrun                 formrun;

        FormTabControl          formTabControl;

        FormGroupControl        formGroupControl;

        FormGridControl         formGridControl;

        FormBuildDataSource     formBuildDataSource;

        TreeNode                treeNodeForm;

        TreeNode                treeNodeTable;

        TreeNode                treeNodeField;

        TreeNodeIterator        iterator;

        FormBuildTabControl     formBuildTabControl;

        FormBuildTabPageControl formBuildTabPageControl;

        FormBuildTabPageControl formBuildTabPageControl2;

        FormBuildGridControl    formBuildGridControl;

        str                     fieldName;

        str                     caption;

        str                     myTableName;

        int                     i;

        DictTable               dictTable;

;

 

        dictTable   = new DictTable(mytableId);

        form = new Form();

        form.name(dictTable.name());

 

        myTableName = tableId2Name(mytableId);

        formBuildDataSource = form.addDataSource(myTableName);

        formBuildDataSource.table(mytableId);

 

        formBuildDataSource.allowCreate(true);

        formBuildDataSource.allowDelete(true);

        formBuildDataSource.allowEdit(true);

 

        formBuildDesign = form.addDesign("Design");

        formBuildDesign.topMode(); // Auto

        formBuildDesign.leftMode(); // Auto

        formBuildDesign.widthMode(); // Auto

        formBuildDesign.heightMode(); // Auto

        formBuildDesign.windowType();

 

        formBuildDesign.caption(dictTable.name());

 

 

        formBuildDesign.titleDatasource(formbuilddatasource.id());

 

 // Add tabbed page controls, a grid control, and string controls.

            formBuildTabControl =

         formBuildDesign.addControl(FormControlType::Tab, "Overview");

 

            formBuildTabPageControl =

         formBuildTabControl.addControl(FormControlType::TabPage, "Overview");

            formBuildTabPageControl.caption("Overview");

 

            formBuildTabPageControl2 =

         formBuildTabControl.addControl(FormControlType::TabPage,"Details");

            formBuildTabPageControl2.caption("Details");

 

        formBuildGridControl = formBuildTabPageControl.addControl(FormControlType::GRID, "Grid");

        formBuildGridControl.dataSource(myTableName);

        formBuildGridControl.widthMode(1); // Column width

        formBuildGridControl.heightMode(1); // Column height

 

        treeNodeTable=TreeNode::findNode(#TablesPath + "\" + myTableName + "\Fields");

        iterator=treeNodeTable.AOTiterator();

        treeNodeField =iterator.next();

 

        while(treeNodeField && i <=6 )

        {

            fieldName=treeNodeField.treeNodeName() ;

 

            if (i==6)

            {

                formBuildTabPageControl2.addDataField(formBuildGridControl.dataSource(), fieldname2id(tablename2id(myTableName),fieldName));

            }

            else

            {

                formBuildGridControl.addDataField(formBuildGridControl.dataSource(), fieldname2id(tablename2id(myTableName),fieldName));

            }

 

            treeNodeField = iterator.next();

            i++;

        }

 

        args = new Args();

        args.object(form);

        formRun = classFactory.formRunClass(args);

        formRun.init();

        formRun.run();

        formRun.wait();

 

}

 

client static void main(Args args)

{

    tableId                 tableId;

    SysContextMenu          sysContextMenu;

    TreeNode                treeNode;

    PSShowFormForTable      psShowFormForTable;

    ;

 

    if (SysContextMenu::startedFrom(args))

    {

        sysContextMenu  = args.parmObject();

        treeNode        = sysContextMenu.first();

        tableId         = SysTableBrowser::treeNode2TableId(treeNode);

    }

 

    if (tableId)

    {

        psShowFormForTable = new PSShowFormForTable();

        psShowFormForTable.createForm(tableId);

    }

}

 

Creation of ContextMenu for above class:

 

Drag the above class to the action menu items, for creating the action menu item.

AOT àMenu ItemsàAction

 

Provide the label as Form browser and save this action menu item.

 

Place this action menu item under SysContextMenu.

 

Open SysContextMenu from AOTàMenus then drag and drop the above action menu item to the SysContextMenu as shown in below figure.

We have to show this context menu item for tables only, not for all the objects in AOT.

 

For this go to the following method.

AOT àClassesàSysContextMenuàverifyItem

 

Add the following code under the MenuItemType Actions case

 

case MenuItemType::Action:

               

 

case menuitemactionstr(PSShowFormForTable):

                if  (_firstType &&_firstType == UtilElementType::Table)

                {

                    return 1;

                }

 

                return 0;

 

Note: Here on the Form browser I am showing only 6 fields on Overview tab and 1 field on Details tab.

Depends on the requirement, we can change the number of fields in above class.

 

 

Advantage: The table browser will be opened with in the Ax, where as this form browser will be opened outside of Ax work space (as Ax-Forms). We can do the analysis on the table data in form browser very easily.

 

Thinking smile

Advertisements
Categories: DynamicsAx Utilities
  1. October 5, 2010 at 8:56 am

    A nice work. But the form ebedded/free form effect can also be changed directly for the table browser. Goto the Form SysTableBrowser\design and change the property called WindowsType from value ‘Popup’ to value ‘Standard’.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: