Programming forms with the Form Script
With the Form Script you validate and supplement input without modifying netERP itself.
Design and code
In the Form Designer, F12 switches between Design and Code. F9 checks the script, F1 opens the help “What can the script do?” with 35 examples that you insert by double-clicking. The language is Pascal (netPascalScript) with English identifiers.
Events
- Form: BeforeOpen, AfterOpen, BeforeSave, AfterSave, BeforeClose, OnValidate.
- Field: OnEnter, OnExit, OnChange, OnClick.
In the object inspector, (new) on the “Events” tab creates the appropriate routine, for example FormBeforeSave. Empty routines are removed by netERP when saving.
Example
procedure FormBeforeSave(Sender: TObject);
begin
if Form.Field('description') = '' then
Form.Cancel('Please enter a description.');
end;
procedure CodeOnExit(Sender: TObject);
begin
Form.SetField('code', UpperCase(Form.Field('code')));
Form.SetEnabled('zip', Form.Field('country') = 'DE');
end;
What the script can do
Read and set fields (Form.Field, Form.SetField), show or hide fields or lock them (SetVisible, SetEnabled), set focus, open a section, display messages and prompts (Message, Confirm) and abort saving or closing (Form.Cancel). Form.IsNew, Form.Module and Form.Id provide information about the record. Field keys come from the form design.
An error in the script is reported once; the form remains usable. Only Form.Cancel aborts an action.
