Creating a Customer Form at Run Time in X++
The job “CustomerForm” creates a customer form at run time in x++. In the form, I have used two datasources “CustTable” and “DirPartyTable”. I have also shown how to add menuitemfunctions in a form through X++.
Here is the code in X++:
public static void CustomerForm(Args _args)
{
//Initialization
DictTable dictTable;
DictTable dictTable1;
Form form;
FormBuildDesign design;
FormBuildDataSource formBuildDataSource;
FormBuildDataSource formBuildDataSource1;
FormBuildActionPaneControl actionPane;
FormBuildActionPaneTabControl actionPaneTab;
FormBuildButtonGroupControl buttonGroup1;
FormBuildButtonGroupControl buttonGroup2;
FormBuildCommandButtonControl CommandNew;
FormBuildCommandButtonControl CommandDelete;
FormBuildMenuButtonControl CustomerButton;
FormBuildFunctionButtonControl NewCustomerButton;
FormBuildFunctionButtonControl ForecastButton;
FormBuildGroupControl Grp;
FormBuildGridControl grid;
FormBuildGroupControl grpBody;
Args args;
FormRun formRun;
#task
{
//Initialization
DictTable dictTable;
DictTable dictTable1;
Form form;
FormBuildDesign design;
FormBuildDataSource formBuildDataSource;
FormBuildDataSource formBuildDataSource1;
FormBuildActionPaneControl actionPane;
FormBuildActionPaneTabControl actionPaneTab;
FormBuildButtonGroupControl buttonGroup1;
FormBuildButtonGroupControl buttonGroup2;
FormBuildCommandButtonControl CommandNew;
FormBuildCommandButtonControl CommandDelete;
FormBuildMenuButtonControl CustomerButton;
FormBuildFunctionButtonControl NewCustomerButton;
FormBuildFunctionButtonControl ForecastButton;
FormBuildGroupControl Grp;
FormBuildGridControl grid;
FormBuildGroupControl grpBody;
Args args;
FormRun formRun;
#task
//Adding DataSources
dictTable1 = new DictTable(tableNum(CustTable));
dictTable = new DictTable(tableNum(DirPartyTable));
form = new Form();
form.name(“Customer Overview”);
dictTable1 = new DictTable(tableNum(CustTable));
dictTable = new DictTable(tableNum(DirPartyTable));
form = new Form();
form.name(“Customer Overview”);
formBuildDataSource = form.addDataSource(dictTable.name());
formBuildDataSource.table(dictTable.id());
formBuildDataSource.table(dictTable.id());
formBuildDataSource1 = form.addDataSource(dictTable1.name());
formBuildDataSource1.table(dictTable1.id());
//Building Form Design
design = form.addDesign(‘Design’);
design.caption(“Overview”);
design.style(FormStyle::SimpleList);
design.titleDatasource(formBuildDataSource.id());
//Adding Action Pane and Buttons
actionPane = design.addControl(
FormControlType::ActionPane, ‘ActionPane’);
formBuildDataSource1.table(dictTable1.id());
//Building Form Design
design = form.addDesign(‘Design’);
design.caption(“Overview”);
design.style(FormStyle::SimpleList);
design.titleDatasource(formBuildDataSource.id());
//Adding Action Pane and Buttons
actionPane = design.addControl(
FormControlType::ActionPane, ‘ActionPane’);
actionPane.style(ActionPaneStyle::Strip);
actionPaneTab = actionPane.addControl(FormControlType::ActionPaneTab, ‘ActionPaneTab’);
actionPaneTab = actionPane.addControl(FormControlType::ActionPaneTab, ‘ActionPaneTab’);
buttonGroup1 = actionPaneTab.addControl(FormControlType::ButtonGroup, ‘NewDeleteGroup’);
buttonGroup2 = actionPaneTab.addControl(FormControlType::ButtonGroup, ‘ButtonGroup’);
buttonGroup2 = actionPaneTab.addControl(FormControlType::ButtonGroup, ‘ButtonGroup’);
CommandNew = buttonGroup1.addControl(FormControlType::CommandButton, ‘NewButton’);
CommandNew.buttonDisplay(FormButtonDisplay::TextAndImageLeft);
CommandNew.normalImage(’11045′);
CommandNew.imageLocation(SysImageLocation::EmbeddedResource);
CommandNew.primary(NoYes::Yes);
CommandNew.command(#taskNew);
CommandNew.buttonDisplay(FormButtonDisplay::TextAndImageLeft);
CommandNew.normalImage(’11045′);
CommandNew.imageLocation(SysImageLocation::EmbeddedResource);
CommandNew.primary(NoYes::Yes);
CommandNew.command(#taskNew);
CommandDelete = buttonGroup1.addControl(FormControlType::CommandButton, ‘NewButton’);
CommandDelete.text(“Delete”);
CommandDelete.buttonDisplay(FormButtonDisplay::TextAndImageLeft);
CommandDelete.normalImage(’10121′);
CommandDelete.imageLocation(SysImageLocation::EmbeddedResource);
CommandDelete.saveRecord(NoYes::Yes);
CommandDelete.primary(NoYes::Yes);
CommandDelete.command(#taskDeleteRecord);
CommandDelete.text(“Delete”);
CommandDelete.buttonDisplay(FormButtonDisplay::TextAndImageLeft);
CommandDelete.normalImage(’10121′);
CommandDelete.imageLocation(SysImageLocation::EmbeddedResource);
CommandDelete.saveRecord(NoYes::Yes);
CommandDelete.primary(NoYes::Yes);
CommandDelete.command(#taskDeleteRecord);
CustomerButton = buttonGroup2.addControl(FormControlType::MenuButton, ‘CustomerquickCreate’);
CustomerButton.helpText(“Create New Customer”);
CustomerButton.text(“Customer”);
CustomerButton.helpText(“Create New Customer”);
CustomerButton.text(“Customer”);
NewCustomerButton = CustomerButton.addControl(FormControlType::MenuFunctionButton, ‘CustomerquickCreate’);
NewCustomerButton.text(‘New’);
NewCustomerButton.saveRecord(NoYes::No);
NewCustomerButton.dataSource(formBuildDataSource.id());
NewCustomerButton.menuItemName(menuitemDisplayStr(CustomerquickCreate));
ForecastButton = buttonGroup2.addControl(FormControlType::MenuFunctionButton, ‘SalesForecast’);
ForecastButton.text(‘Forecast’);
ForecastButton.saveRecord(NoYes::No);
ForecastButton.menuItemName(menuitemDisplayStr(ForecastSalesGroup));
//Body
grpBody = design.addControl(FormControlType::Group, ‘Body’);
grpBody.heightMode(FormHeight::ColumnHeight);
grpBody.columnspace(0);
grpBody.style(GroupStyle::BorderlessGridContainer);
NewCustomerButton.text(‘New’);
NewCustomerButton.saveRecord(NoYes::No);
NewCustomerButton.dataSource(formBuildDataSource.id());
NewCustomerButton.menuItemName(menuitemDisplayStr(CustomerquickCreate));
ForecastButton = buttonGroup2.addControl(FormControlType::MenuFunctionButton, ‘SalesForecast’);
ForecastButton.text(‘Forecast’);
ForecastButton.saveRecord(NoYes::No);
ForecastButton.menuItemName(menuitemDisplayStr(ForecastSalesGroup));
//Body
grpBody = design.addControl(FormControlType::Group, ‘Body’);
grpBody.heightMode(FormHeight::ColumnHeight);
grpBody.columnspace(0);
grpBody.style(GroupStyle::BorderlessGridContainer);
grid = grpBody.addControl(FormControlType::Grid, “Grid”);
grid.dataSource(formBuildDataSource.name());
grid.widthMode(FormWidth::ColumnWidth);
grid.heightMode(FormHeight::ColumnHeight);
grid.addDataField(formBuildDataSource.id(), fieldNum(DirPartyTable,Name));
grid.addDataField(formBuildDataSource1.id(), fieldNum(CustTable,AccountNum));
grid.addDataField(formBuildDataSource.id(), fieldNum(DirPartyTable,LanguageId));
grid.dataSource(formBuildDataSource.name());
grid.widthMode(FormWidth::ColumnWidth);
grid.heightMode(FormHeight::ColumnHeight);
grid.addDataField(formBuildDataSource.id(), fieldNum(DirPartyTable,Name));
grid.addDataField(formBuildDataSource1.id(), fieldNum(CustTable,AccountNum));
grid.addDataField(formBuildDataSource.id(), fieldNum(DirPartyTable,LanguageId));
Grp = design.addControl(FormControlType::Group, ‘Group’);
ForecastButton = Grp.addControl(FormControlType::MenuFunctionButton, ‘SalesForecast’);
ForecastButton.text(‘Forecast’);
ForecastButton.menuItemName(menuitemDisplayStr(ForecastSalesGroup));
ForecastButton.text(‘Forecast’);
ForecastButton.menuItemName(menuitemDisplayStr(ForecastSalesGroup));
args = new Args();
args.object(form);
args.object(form);
formRun = classFactory.formRunClass(args);
formRun.init();
formRun.run();
formRun.detach();
}
formRun.init();
formRun.run();
formRun.detach();
}
Comments
Post a Comment