Events
Events can be used as communication between components and are typically raised when something has occurred. You can read more about Events by reading our Introduction to Events guide.
Event Types
Event
{
organizationId: string,
id: string,
name: string,
attributes: Record<string, string>,
timestampUtc: datetime
}
CreateEventOptions
{
timestampUtc: datetime,
attributes: Record<string, string>
}
QueryEventOptions
{
names: string[],
startUtc: datetime,
endUtc: datetime,
attributes: Record<string, string>
}
createEvent
Read-only Mode
This function is not available in read-only mode.
Creates a new custom Event.
createEvent(name, options)
Parameters
Name | Type | Description | Optional |
---|---|---|---|
name | string | The name of the Event. | ❌ |
options | CreateEventOptions | Options to create the Event with. | ✔ |
Returns The created Event.
Example
// Create an Event with attributes
var event = createEvent('status-changed', {
attributes: {
"source": "udf",
"status": 1
}
});
getEvent
Gets an Event by its identifier.
getEvent(eventId)
Parameters
Name | Type | Description |
---|---|---|
eventId | string | The identifier of the Event. |
Returns The Event with the specified identifier.
Example
var event = getEvent('c2012196-4349-408e-9dd1-8107b61fd8fb');
getEvents
Gets a collection of Events using optional query criteria.
getEvents(options)
Parameters
Name | Type | Description |
---|---|---|
options | QueryEventOptions | Options for querying Events. |
Returns A collection of Events which meet the query criteria.
Example
// Query all 'status-changed' Events which a udf source.
var udfEvents = getEvents({
names: ['status-changed'],
attributes: {
source: 'udf'
}
});
// Query all 'status-changed' Events within the last week.
var date = new Date();
var timeFrameEvents = getEvents({
names: ['status-changed'],
startUtc: date - 7,
endUtc: date
});