This is an example of a
RunBaseBatch class that demonstrates how to change another dialog fields in run time.
Let's say we have a parameter of enum type, which selects the right business logic inside of
Run method.
It is a good idea to change the main static text of the dialog as well as the batch caption that serves as a description for an eventual batch job (and tasks).
After adding this field in
Dialog method we need to override
Modified method for this field.
protected Object dialog()
{
FormComboBoxControl combobox;
dlg = super();
dialogEventType = dlg.addFieldValue(EnumStr(uapInterfaceEventType), eventType );
// to add details to the caption and task description in batch tasks
dialogEventType.registerOverrideMethod(methodstr(FormStringControl, modified), methodstr(tmxRunBaseBatchSample, eventType_modified), this);
// to avoid user input in the field
combobox = dialogEventType.control();
combobox.comboType(1);
return dlg;
}
In
eventType_modified method we call two additional methods to apply the user input respectively for
BatchCaption and
MainInstruction fields.
private boolean eventType_modified(FormStringControl _control)
{
boolean ret = _control.modified();
if(ret)
{
this.setBatchCaption();
this.setMainInstruction();
}
return ret;
}
To get access to these dialog fields we use two different approaches. We find
BatchCaption form control recursively inside of batch tab page based on its type.
private void setBatchCaption()
{
FormStringControl batchCaptionControl;
// to get the batch caption control; any of them if many
batchCaptionControl = this.getBatchCaptionControl(dlg);
if (batchCaptionControl)
{
batchCaptionControl.text(this.caption());
}
}
// returns the batch caption form control if any in the dialog
private FormStringControl getBatchCaptionControl(DialogRunbase _dialog)
{
FormStringControl batchCaptionControl;
// recursive routine to look for the right form control of BatchCaption EDT
Object findBatchCaptionControl(Object _parentObject)
{
int i;
Object childControl;
Object foundControl;
for (i = 1; i <= _parentObject.controlCount(); i++)
{
childControl = _parentObject.controlNum( i );
// this is our boy
if( childControl is FormStringControl && childControl.extendedDataType() == extendedTypeNum(BatchCaption))
{
// time to get up
return childControl;
}
else
{
if (childControl is FormGroupControl)
{
foundControl = findBatchCaptionControl(childControl);
if (foundControl)
{
return foundControl;
}
}
}
}
// just step back to check others
return null;
}
/////// main routine /////////////////////////////////////////////////////////////
if( _dialog && _dialog.batchDialogTabPage())
{
batchCaptionControl = findBatchCaptionControl(_dialog.batchDialogTabPage().control());
}
return batchCaptionControl;
}
As to
MainInstruction we get it by its name.
private void setMainInstruction()
{
FormStaticTextControl mainInstructionControl;
FormGroupControl formGroup = dlg.mainFormGroup();
// to get the main instuction static text of the dialog
mainInstructionControl = dlg.dialogForm().runControl('MainInstruction');
if (mainInstructionControl)
{
mainInstructionControl.text(this.caption());
}
}
Now when the user changes the event type, two other fields change respectively.
You can find the whole project
here.