Validation scripts

When writing validation scripts that execute on the server, the following system variables can help you trap information and provide feedback.

  • Values( ). Holds the inbound values of data coming into the system. It allows you to read any variable in the QueryString in CreateScripts. You can test for the dominant key and context.

    Copy
    var x = Values("Key0");
    Valid = false;
    ErrorStr = x;
  • Valid. Determines whether the ErrorStr value should be displayed on the screen. The default value is True. When set to False, it marks the current entry as invalid. Valid set to False has the following behavior in different parts of the system:
    • It displays an ErrorStr in create scripts and blocks the commitment of data in validate scripts.
    • It controls the display of workflow rule buttons in Primary, Transition, and Global workflow rules.
    • It causes a conditional rule to execute an alternative set of actions.
    • In Table Level and Entity Level scripts that update records in response to an action, it can set ErrorStr to the browser, or can block the entire transaction.
  • ErrorStr. Returns the string in the error content bar at the top of the screen.

The following example validates a field value when a user is specifying details for an opportunity:

Copy
if (Values('oppo_type')="Mix")
{
    Valid = false;
    ErrorStr = 'This Mix type is temporarily not supported';
}

This script checks the value in the oppo_type field, and an action is taken if the opportunity type is Mix. This script only validates the value of the specified field, other fields are ignored.

If the oppo_type field value is invalid (Valid = false), an error message (ErrorStr = 'This Mix type is temporarily not supported';) is displayed in a red bar at the top of the screen.

This example tests onscreen information only. You can use other blocks accessible through the API to base validation on entity information not currently displayed onscreen. Also, the CRMEntryBlock object's properties such as Required, ReadOnly, MaxLength, CreateScript, OnChangeScript, and ValidateScript enable you to control and respond to values entered into a screen.