Clear Cutover Get a quote

Customization

SyteLine form scripts for validation: catch bad input before it becomes a ticket

Applies to: SyteLine 8, 9 and 10, and CloudSuite Industrial (WinStudio / Mongoose forms). Scripting needs Site Developer or equivalent editing rights.

Short answer

SyteLine gives you three places to stop bad input. Validators are reusable checks attached to components, best for "this value must exist" or "must be in this list". Form scripts run from a form's event handlers, best for checks that depend on several fields or need a warning before something risky runs. IDO-level rules run on the server for every save, including integrations and imports. A form script runs through an event handler with the Run Script response type. The handler passes it a comma-separated list of parameters, which the script reads with GetParameter(0), GetParameter(1) and so on. The script returns 0 for success and non-zero for failure. Use form scripts for user guidance, not for rules that must never be bypassed: anything that doesn't come through the form never runs them.

Pick the right layer

Need Best tool Why
"This code must exist / be in a list / be in range" Validator Reusable across forms and components; no code
"If field A is X, field B is required" or "warn before running this" Form script Can look at several fields and talk to the user
"This must be true no matter how the data arrives" IDO-level logic (extension class, or the IDO's own rules) Runs on the server for every save, including APIs and imports

The mistake to avoid: putting a business-critical rule only in a form script. A data import, an integration or the REST API never opens the form, so the script never runs.

How a Run Script handler works

In Design Mode you attach an event handler to a form or component event, and choose Run Script as its response type. Infor's documentation for this response type describes three things:

  • You name the script to run.
  • You pass parameters as a comma-delimited list. Each one can be a literal, a property, a variable or a component value.
  • The script reports back: return 0 for success, non-zero for failure.

Inside the script, read the parameters in order:

Dim first As String = GetParameter(0)
Dim second As String = GetParameter(1)

Passing values as parameters, rather than reaching into the form from the script, keeps the script reusable. The same check can serve several forms.

Worked example: catch a mistyped range before it runs

This example comes from a real incident. On SyteLine 9, a packing slip run was entered with the order range x1004 to x10005, one extra digit. It ran for days and stopped invoicing. The full story is in Why a SyteLine task runs for days.

A simple check would have caught it: when the "to" value is longer than the "from" value, warn before submitting. As a script that receives the two range values as parameters:

' Warns when a range looks wrong before a long-running task is submitted.
' Parameters: 0 = range start, 1 = range end
' Returns 0 to continue, 1 to stop.
Function Main() As Integer
    Dim rangeStart As String = GetParameter(0).Trim()
    Dim rangeEnd As String = GetParameter(1).Trim()

    ' Blank end = "everything from here on": never run that silently
    If rangeEnd = "" Then
        Application.ShowMessage("The 'to' value is blank, so this will process every record from the start value onwards. Please enter an end value.")
        Return 1
    End If

    ' Different lengths usually mean a typo, e.g. x1004 to x10005
    If rangeEnd.Length <> rangeStart.Length Then
        Application.ShowMessage("The range '" & rangeStart & "' to '" & rangeEnd & "' has values of different lengths. Please check for a typo before running.")
        Return 1
    End If

    Return 0
End Function

Wire it to the event that fires when the user submits the task on that form, before the event handler that actually starts the task. Pass the two range components as the parameters, and make sure the sequence stops when the script returns non-zero.

Treat this as a pattern, not paste-ready code. Component names, event names and the exact scripting template differ between forms and versions. Build it in a test environment, check it against the WinStudio scripting reference for your version, and test it with good ranges, bad ranges and blank values before moving it to production.

Habits that prevent script trouble

1. Save at the right scope

A script saved while your editing scope is User works only for you. Set the scope to Site (or the right Group) before you start. See Why SyteLine form changes disappear.

2. Don't make a change event change itself

If a script runs when a field changes and then sets that same field, it can trigger itself again and again, and the form appears to hang. Only write to a component when the value actually needs to change, and prefer storing working values in form variables (ThisForm.Variables("Name").Value) rather than visible fields.

3. Keep scripts light

Scripts run while the user waits. Don't load large collections or run heavy server calls on events that fire often, such as every field change. If the logic needs real data work, put it in an IDO method or stored procedure and call it once, at the point where it matters.

4. Warn, explain, and say what to do

A good validation message says what's wrong and what to do: "The 'to' value is blank… please enter an end value", not "Invalid input".

5. Keep a copy and a register

Copy each script's source somewhere version-controlled, and list it in your register of customised forms with what it does and why. Upgrades are much easier when you know which forms carry scripts. FormSync treats them as major customisations.

6. Back up important rules on the server

If the rule matters for data quality, such as "orders of type X must have a carrier", put a server-side version in the IDO layer too. The form script gives the friendly message. The server rule makes sure imports and integrations can't break it.

FAQ

How do I add validation to a SyteLine form?

For simple checks, attach a validator to the component. For checks involving several fields, or a warning before running something, use an event handler with the Run Script response type and a script that returns 0 for success and non-zero for failure.

How does a SyteLine script read event handler parameters?

With GetParameter: GetParameter(0) is the first value in the handler's comma-separated parameter list, GetParameter(1) the second, and so on.

Will a SyteLine form script stop bad data from imports or integrations?

No. Form scripts only run when someone uses the form. Rules that must always apply belong in the IDO layer on the server.

Why does my SyteLine form script only work for me?

It was probably saved while your Design Mode editing scope was User. Save it again at Site or Group scope.

Systems I work on