How to build a dynamic form in Dynamics AX 2012 Through X++



How to build a dynamic form in Dynamics AX 2012 Through X++


        #Task
        DictTable                                              dictTable;
        Form                                                     form;
        FormBuildDesign                                 formBuildDesign;
        FormBuildDataSource                         formBuildDataSource;
        FormBuildActionPaneControl             formBuildActionPaneControl;
        FormBuildActionPaneTabControl       formBuildActionPaneTabControl;
        FormBuildButtonGroupControl          formBuildButtonGroupControl_NewDelete;
        FormBuildButtonGroupControl          formBuildButtonGroupControl_Related;
        FormBuildCommandButtonControl    formBuildCommandButtonControl_New;
        FormBuildCommandButtonControl    formBuildCommandButtonControl_Del;
        FormBuildMenuButtonControl           formBuildMenuButtonControl_Items;
        FormBuildFunctionButtonControl      formBuildFunctionButtonControl_Items;
        FormBuildGroupControl                     formBuildGroupControl_Body;
        FormBuildGridControl                        formBuildGridControl_ItemGroup;       
        Args                                                     args;
        FormRun                                             formRun;
        
        dictTable = new DictTable(tableNum(InventItemGroup));


        form = new Form();
        form.name('TestDynamic');

        
        formBuildDataSource = form.addDataSource(dictTable.name());
        formBuildDataSource.table(dictTable.id());

      
        formBuildDesign = form.addDesign('Design');
        formBuildDesign.caption('Test Form');
        formBuildDesign.style(FormStyle::SimpleList);
        formBuildDesign.titleDatasource(formBuildDataSource.id());


      
        formBuildActionPaneControl                  = formBuildDesign.addControl(FormControlType::ActionPane, 'ActionPane_Main');
        formBuildActionPaneControl.style(ActionPaneStyle::Strip);
        formBuildActionPaneTabControl               = formBuildActionPaneControl.addControl(FormControlType::ActionPaneTab, 'ActionPaneTab_General');

        formBuildButtonGroupControl_NewDelete       = formBuildActionPaneTabControl.addControl(FormControlType::ButtonGroup, 'ButtonGroup_NewDelete');
        formBuildButtonGroupControl_Related         = formBuildActionPaneTabControl.addControl(FormControlType::ButtonGroup, 'ButtonGroup_Related');

        
        formBuildCommandButtonControl_New = formBuildButtonGroupControl_NewDelete.addControl(FormControlType::CommandButton, 'CommandButton_New');
        formBuildCommandButtonControl_New.primary(NoYes::Yes);
        formBuildCommandButtonControl_New.command(#taskNew);


      
        formBuildCommandButtonControl_Del = formBuildButtonGroupControl_NewDelete.addControl(FormControlType::CommandButton, 'CommandButton_Del');
        formBuildCommandButtonControl_Del.text("Delete");
        formBuildCommandButtonControl_Del.saveRecord(NoYes::Yes);
        formBuildCommandButtonControl_Del.primary(NoYes::Yes);
        formBuildCommandButtonControl_Del.command(#taskDeleteRecord);



        formBuildMenuButtonControl_Items = formBuildButtonGroupControl_Related.addControl(FormControlType::MenuButton, 'Related');
        formBuildMenuButtonControl_Items.helpText('Get related Information.');
        formBuildMenuButtonControl_Items.text("Related");
        

        formBuildFunctionButtonControl_Items = formBuildMenuButtonControl_Items.addControl(FormControlType::MenuFunctionButton, 'Menu_Items');
        formBuildFunctionButtonControl_Items.text('Items');
        formBuildFunctionButtonControl_Items.saveRecord(NoYes::No);
        formBuildFunctionButtonControl_Items.dataSource(formBuildDataSource.id());
        formBuildFunctionButtonControl_Items.menuItemName(menuitemDisplayStr(ForecastInvent));
        


        formBuildGroupControl_Body = formBuildDesign.addControl(FormControlType::Group,'Group_Body');
        formBuildGroupControl_Body.heightMode(FormHeight::ColumnHeight);        
        formBuildGroupControl_Body.columnspace(0);
        formBuildGroupControl_Body.style(GroupStyle::BorderlessGridContainer);


        formBuildGridControl_ItemGroup = formBuildGroupControl_Body.addControl(FormControlType::Grid, "ItemGroup_Grid");
        formBuildGridControl_ItemGroup.dataSource(formBuildDataSource.name());
        formBuildGridControl_ItemGroup.showRowLabels(false);
        formBuildGridControl_ItemGroup.widthMode(FormWidth::ColumnWidth);
        formBuildGridControl_ItemGroup.heightMode(FormHeight::ColumnHeight);

        
        //Fields
        formBuildGridControl_ItemGroup.addDataField(formBuildDataSource.id(), fieldNum(InventItemGroup,ItemGroupId));
        formBuildGridControl_ItemGroup.addDataField(formBuildDataSource.id(), fieldNum(InventItemGroup,Name));
       
        args = new Args();
        args.object(form);
        formRun = classFactory.formRunClass(args);
        formRun.init();
        formRun.run();
        formRun.detach();
    }

Comments

Popular posts from this blog

How to loop through enum in dynamics ax 2012 using x++

How to read from csv file in Dynamics AX 2012 Through X++

How to Create Transfer Journal in Dynamics AX 2012 Through X++