You have been redirected from an outdated version of the article. Below is the content available on this topic. To view the old article click here.

error()

Usage

error(propertyKey, token, detail)
error(propertyKey, token)

Description
This method can be used to signal an error condition during Scripting execution. It is mainly used in Entity Callback Functions like onCreate() or onSave() to allow the user to implement custom validation logic.

Examples

${error('name', 'name_not_allowed')}
${error('name', 'name_not_allowed', 'The given name is not allowed.')}

results in an HTTP 422 Unprocessable Entity error.

Search results for "error()"

mail_get_error()

New in v.3.6: Allows to retrieve the last error message when sending a mail.

${mail_get_error()}

error()

This method can be used to signal an error condition while scripting execution. It is mainly used in entity callback functions like onCreate() or onSave() to allow the user to implement custom validation logic.

If an error is raised the current transaction will be rolled back and no changes will be written to the database.

error(propertyKey, token, detail)
error(propertyKey, token)

has_error()

Allows checking if an error has been raised in the scripting context

has_error()

mail_has_error()

New in v.3.6: Allows to check for errors when sending a mail.

${mail_has_error()}

onCreate

  • Is called when an object is created (but the transaction is not yet committed)
  • Multiple onCreate methods can exist per type - every method prefixed with onCreate is called when an object is created (e.g. onCreate01, onCreate02)
  • Schema constraint checks (uniqueness constraint, notNull constraint) are performed after onCreate has run
  • can be rolled back
    • if an error occurs
    • if an error is raised via error() function
    • if a constraint is violated
  • All regular keywords can be used - no special keywords are introduced for this method

Example:

onSave

  • Is called when an object is modified. (Either modification of local attributes of relationships. When a relationship is created, the onSave is triggered for both nodes)
  • creation of an object is not a modification, thus the onSave is not run when an object is created (even if the object is ‘modified’ in onCreate)
  • Multiple onSave methods can exist per type - every method prefixed with onSave is called when an object is created (e.g. onSave01, onSave02)
  • Schema constraint checks (uniqueness constraint, notNull constraint) are performed after onSave has run
  • can be rolled back
    • if an error occurs
    • if an error is raised via error() function
    • if a constraint is violated
  • All regular keywords can be used - one special keyword is introduced for this method

The state of the object in the scripting environment represents the state of the object after the modification. To get information about the previous state the keyword modifications can be used.

Keyword Value
modifications Object containing the modifications made to the object in the current operation

Example:

onDelete

  • is run after an object has been deleted (but the transaction has not yet been committed)
  • Using the this keyword results in an error as the object has already been deleted
  • can be rolled back
    • if an error occurs
    • if an error is raised via scripting See <a data-id="651d6bf220e3422488fa61a34109745c" class="mention">error()</a> function
  • All regular keywords can be used - no special keywords are introduced for this method