To create the create dialog, follow these steps:
- Create a new form, suffixing the details form name with Create; for example, ConWHSVehicleServiceTableCreate.
- Drag the tables associated with the header record to the form's Data Source node; in our example, the ConWHSVehicleServiceTable table.
- Set the properties for the ConWHSVehicleServiceTable data source as follows:
Property |
Value |
Allow Delete |
No |
Allow Notify |
No: we want this to act as a single record dialog and disable most of the events that the data source performs for us |
Auto Search |
No |
Insert At End |
No |
Insert If Empty |
No |
Delay Active |
No |
We will need to control the behavior of the data source in this case, as it will be called from another, so we have to disable certain user options and events.
- Override the form's init method and write the following piece of code:
// global to the form / element
ConWHSVehicleServiceTableForm serviceTableForm;
ConWHSVehicleServiceTableType serviceTableType;
/// <summary>
/// the form must be called with a form handler class
/// </summary>
public void init()
{
if (element.args())
{
if (element.args().caller() is
ConWHSVehicleServiceTableForm)
{
serviceTableForm = element.args().caller();
}
}
if (!serviceTableForm)
{
//Form was incorrectly called
throw error ("@SYS22996");
}
super();
serviceTableType = ConWHSVehicleServiceTable.type();
}
- Continue to override the run and close form methods with the following lines of code:
public void run()
{
ConWHSVehicleServiceTable.clear();
ConWHSVehicleServiceTable_DS.create();
super();
}
public void close()
{
if(serviceTableType)
{
serviceTableType.formMethodClose();
}
super();
}
- We will now need to adjust some of the ConWHSVehicleserviceTable data source's methods; start this by overriding the research method and writing the following piece of code:
public void research(boolean _retainPosition = false)
{
//super(_retainPosition) Disable the refresh feature.
}
public void reread()
{
// Allow the DS to reread only if saved
if (ConWHSVehicleServiceTable.RecId)
{
super();
}
}
void write()
{
// this ensures that the form close if
// the number sequence can't be used
// and passes a null record back
try
{
serviceTableType.formMethodDataSourceWrite(
element, this);
super();
}
catch (Exception::Error)
{
ConWHSVehicleServiceTable.RecId = 0;
serviceTableForm.ParmServiceTableCreated(
ConWHSVehicleServiceTable);
element.close();
throw Exception::Error;
}
this.reread();
this.refresh();
// update the handler form with the new record.
serviceTableForm.ParmServiceTableCreated(
ConWHSVehicleServiceTable);
}
void create(boolean append = false)
{
// only allow create if the current record
// hasn't been saved
if (!ConWHSVehicleServiceTable.ServiceId)
{
super(append);
serviceTableType.formMethodDataSourceCreate(
element, this);
}
}
- Apply the Dialog - basic pattern to the Design node.
- Complete the Design properties, but set the Caption property to New vehicle service order.
- Complete the form layout according to the pattern. Use the following as a guide:
- Within the Dialog Commit Content pattern element, use the Fields and Field Groups pattern, and add fields and field groups as desired.
- The OK and Cancel buttons in the pattern are Command Buttons, and the pattern will hide the Command property. Make the OK button the default button.
- Next, open the ConWHSVehicleServiceTableForm class and add the following methods:
public str CreateFormName()
{
return formStr(ConWHSVehicleServiceTableCreate);
}
public boolean create()
{
Args args = new Args();
FormRun createFormRun;
ConWHSVehicleServiceTable currentRecord;
currentRecord = this.currentRecord();
args.name(this.CreateFormName());
args.caller(this);
createFormRun = classfactory.formRunClass(args);
createFormRun.init();
createFormRun.run();
if (!createFormRun.closed())
{
createFormRun.wait();
}
if (createFormRun.closedOk())
{
return true;
}
else
{
serviceTableCreated = currentRecord;
return false;
}
}
- Open the ConWHSVehicleServiceTable form, open the code for the ConWHSVehicleServiceTable.active method, and change it so it reads as follows:
public void create(boolean _append = false)
{
ConWHSVehicleServiceTable newServiceTable;
if(formHandler.create())
{
newServiceTable =
formHandler.ParmServiceTableCreated();
if (newServiceTable)
{
super(_append);
ConWHSVehicleServiceTable.data(
newServiceTable);
this.setCurrent();
}
}
}
- Now we should save all, build, and test. You should test the New button on the Vehicle service form, and also the New button on the workspace.