Validations

Scripting Custom Scripts

Validations are custom scripts that are run server-side for security. You can add custom errors or requirements to your forms, call an external API, or create a submission to another form. The validation script will be run whenever a submission is created or updated, and it will be passed a set of objects for the submission.

Server-side scripts can use the same API structure as client-side scripts. Some obvious exceptions, such as the Navigation object, are not present in the server-side API. However, the same submission object is available.

submission;
submission.fields.field_name.value();
submission.fields.field_name.error("must be between 5 and 20 characters.");

submission.form.permalink();

Validations support the use of asynchronous methods such as $.Deferred and external API calls. Because of this, your script is required to call the finish method when your script is done. By default, validations will time out after 10 seconds. This limit is in place because validations are synchronous and the end-user is waiting on a confirmation from the validation. To request an exception to this time limit, email us at support@sonadier.com.

Integrations.salesforce.get("/services/data/v35.0").done(function(response) {
  console.log("Salesforce API Response:");
  console.log(response);
  finish();
});

If you enable Development Mode, the output of console.log will be returned in an array with the request's response. You can view it from the Networking tab of any modern browser's developer console (F12).

DEVELOPMENT = true;

Validation Errors

If there's an issue that prevents the validation server from functioning, an error will appear at the top of the submission. More information can usually be found by inspecting the request in the Network tab of your browser's Developer Console (F12). Any console logs or errors will be returned in the body of the response. Validation server error messages are listed below:

  • The validation server timed out: Your custom script took too long, or was not resolved using the finish method. Scripts are currently limited to 10 seconds.
  • The validation server could not be reached: The validation server is down or inaccessible. If this message appears, contact support@sonadier.com.
  • There was an error with the custom validation script: An error with your script prevented the validation from resolving. Set Development Mode to true, and check the networking tab to see any related console output from your script. This should let you know where your script stopped working.