// Example of a custom time-based access control mechanism in an account trigger update.
var hour = new Date().getUTCHours();
if (!(hour >= 8 && hour <= 17)) {
throw new Error('Updates are only allowed between 8am and 5pm GMT');
}
// Update the c_random property each time the instance is updated (not directly writable by the account holder).
script.arguments.new.update('c_random', Math.random(), {grant: 8});
Triggers can be setup to run before and/or after creation, update, and deletion of object instances, as well as before and after session authentications (to allow for custom authentication mechanisms).
All before
triggers are run inline, that is they return false or throw an error from the script to cancel the operation. In object instance before
triggers, changes can be made inline to instance properties directly from the script, and made as either the script's calling principal or given a grant. These changes are recorded in the audit logs as separate events.
All before update
trigger code should be idempotent, as they may run more than once during update conflict resolution events.
An after
script runs after the operation that triggered it has completed and is ideally suited for sending notifications. These triggers are guaranteed to run only once.