Browsing posts in: X++ Jobs

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

//Adding DataSources
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());

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’);

actionPane.style(ActionPaneStyle::Strip);
actionPaneTab = actionPane.addControl(FormControlType::ActionPaneTab, ‘ActionPaneTab’);

buttonGroup1 = actionPaneTab.addControl(FormControlType::ButtonGroup, ‘NewDeleteGroup’);
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);

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);

CustomerButton = buttonGroup2.addControl(FormControlType::MenuButton, ‘CustomerquickCreate’);
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);

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));

Grp = design.addControl(FormControlType::Group, ‘Group’);

ForecastButton = Grp.addControl(FormControlType::MenuFunctionButton, ‘SalesForecast’);
ForecastButton.text(‘Forecast’);
ForecastButton.menuItemName(menuitemDisplayStr(ForecastSalesGroup));

args = new Args();
args.object(form);

formRun = classFactory.formRunClass(args);
formRun.init();
formRun.run();
formRun.detach();
}


Finding the occurrence of string within another string through X++

X++ offers a lot of string functions to be used on the strings. Here, we will be using the “strscan” function. The “strscan” searches for a string within another string

————————————————————————————————————-

The strscan function takes the following arguments

Strscan (str text, str characters, int position, int number);

Text: The target string

Characters: The string to be found

Position: The first position in the target string to perform the search

Number: Number of times search will be performed. Normally, it is the length of the original string. If a negative sign is used in this argument, the search operation is performed in the reverse order

————————————————————————————————————-

Below is the code to find any character in a string.

int position;

str targetstring = “ABCD”

position = strscan( targetstring, “CD”,3,strlen(targetstring);

if (position)

{

info(“Found”);

}

else

{

info(“Not Found”);

}