sys.events

Describes event utilities in the Javascript API.

sys.events

The sys.events package encompasses methods intended for the administration of custom events.

triggerEvent(event,data)

This method initiates a custom event within the application, which can be captured by any listener set up to monitor a CUSTOM_EVENT with a name matching the event parameter.

Parameters
NameTypeRequiredDescription
eventstringyesThe name of dispatched custom event.
dataobjectnoMap of properties that will be sent as data of event.
Samples
// trigger `newNote` event with id of record
sys.events.triggerEvent('newNote', {noteId: record.id()});

registerCallback(key, callback, data, options)

This method registers a callback along with its associated data and optional settings into the app’s storage. The first parameter of the callback will be the callback data when the callback was registered. Other params are dynamic and are sent on when calling executeCallback

Parameters
NameTypeRequiredDescription
keystringyesA unique identifier under which the callback data will be stored.
callbackfunctionyesThe main callback function to register.
dataobjectyesAn object containing any associated data. May include nested functions.
optionsobjectnoOptional parameters to configure the storage. The available options are:
- ttl: Indicates the time to live for that key, expressed in milliseconds.
Returns
  • string: The key of the stored callback.
Samples
// Register a callback that logs user data later
sys.events.registerCallback(
  'userLogger',
  function(callbackData,user) {
    sys.logs.info('User logged in: '+ user.name);
    sys.logs.info('Company: '+ callbackData.company);
  },
  {company:"ACME"},
  {ttl: 60000}
);

executeCallback(key, …args)

This method retrieves and executes a previously registered callback from app storage using the provided key. Any additional arguments passed will be forwarded to the callback. After execution, the callback is removed from storage.

Parameters
NameTypeRequiredDescription
keystringyesThe key used to retrieve the callback data from storage.
…argsanynoArguments to be passed to the restored callback function.
Returns
  • any: The return value from the executed callback function.
Samples
// Execute the previously stored 'userLogger' callback
sys.events.executeCallback('userLogger', {name: 'Alice'});