trigger error

System trigger that is activated when a predefined errors occurs.

Declaration: trigger error
Applies to: Entity , Field
Activation: Activated when Uniface detects that one of a predefined set of errors has occurred. For details, see Errors That Activate This Trigger.
Default behavior: If the operation is not explicitly declared, it falls back to a default behavior:
  • In a Static and Dynamic Service Pages, the default behavior is like the following code:

    Entity:

    trigger error
      putitem/id $occproperties(), "SubClass”, "errorstyle"
      putitem/id $occproperties(), "errormsg”, $text("%%$error")
    end
    

    Field:

    trigger error
      putitem/id $fieldproperties(), "SubClass", "errorstyle"
      putitem/id $fieldproperties(), "errormsg", $text("%%$error")
    end
    
  • In other component types, the default behavior is like the following code:
    trigger error
      if ($error != 0)
        message $text(“%%$error”)"
        return -1
     endif
      return 0
    end
    

Behavior upon completion:

None

Description

You can use this trigger to define what should happen when errors occur on the field or entity occurrence. The error number that activated the error trigger is available in $error.

By default, the standard message associated with the error is displayed in the message line. The default message is available in $text; for example, $text("%%$error") returns the default message text.

You can customize the processing associated with these error situations by adding ProcScript to this trigger to check the value of $error and act accordingly. It is important to include an else block that handles all errors that you do not handle.

Important: The error trigger is intended for error handling and should not be used for data I/O, with one exception. You can discard records in the error trigger is when the error that activated the error trigger is 2014, which is returned by webget when new occurrences have been created on the client. In this case, you must explicitly test for before you perform a discard. For more information, see webget.

Errors That Activate This Trigger

The actual entity name is substituted for Entity in the displayed message.

Error Codes that Activate the Entity-Level error Trigger
$error Default message
0102 Not enough occurrences in entity Entity.
0103 Too many occurrences in entity Entity.
0118 More occurrences are not allowed.
0139 Entity EntityA still has restricted links to EntityB.
0147 Validation failed for key.
0153 Validation failed for occurrence.
0148 First occurrence.
0149 Last occurrence.
2004 No modifications allowed on occurrence of this entity.
2009 Occurrence locked.
2012 Occurrence in form does not match database occurrence.
2013 Occurrence does not exist.
2014 New occurrence of entity Entity encountered during processing by webget.

The actual field name is substituted for field in the displayed message.

Error Codes that Activate the Field-level error Trigger
$error Default message
0105 Not allowed to change primary key field.
0119 Error on field field ; illegal ValRep value.
0120 Error on field field ; subfield too large.
0121 Error on field field ; subfield too small.
0122 Error on field field ; incorrect checkdigit.
0123 Error on field field ; illegal format for numeric field.
0124 Error on field field ; illegal format for date field.
0125 Error on field field ; illegal format for time field.
0126 Error on field field ; illegal syntax format.
0127 Error on field field ; illegal entry format.
0128 Error on field field ; subfield too large to check.
0129 Error on field field ; subfield(s) are required.
0130 Error on field field ; too many subfields specified.
0131 Error on field field ; font not allowed.
0133 Error on field field ; ruler/frames not allowed.
0134 Error on field field ; italic not allowed.
0135 Error on field field ; underline not allowed.
0136 Error on field field ; bold not allowed.
0137 Error on field field ; open/close brackets do not match.
0138 Error on field field ; illegal format for floating field.
0140 Validation failed for field .
0150 Requested number of "&" and "|" operators not supported.

error Trigger

The following examples show how the error trigger can provide a more specific message in form components:

; Entity-level 
trigger error
if ($error = 0139)
   message "You must delete all invoices before deleting the customer"
   return -1
else
   message $text($error)
   return -1
endif
end; error
; Field-level
 trigger error
 if ($error = 0105)
   message "You can’t change the company number of an existing company!"
   return -1
 else
   message $text("%%$error")
   return -1
endif
end; error

Related Topics