Event: Update Node

The Event: Update Node allows a workflow to update a one or more existing Events from the current application. If updating a single event, the node optionally allows the updated event to be added to the current workflow payload.

Update Event Node

Note: If updating multiple events, this node will queue the update and continue executing the workflow. If successful, { “success”: true } will be applied to the result path on the payload indicating that the updates have been queued and will be applied shortly.

Node Properties

The configuration for the Event: Update Node requires a query method and parameters in order to select which events to update. It also requires new state parameters to apply to the event for the update.

Update Mode

The first step is selecting a update mode method to use to select an event or group of Events to update. The Event: Update Node has three different options:

  • One Event By ID: You can input a specific event’s ID to retrieve it or use a value on the payload. The ID can be hardcoded in the workflow editor or derived from a property on the current payload.
  • One Event By Query: You can create an advanced query to retrieve a single event. This query is templatable, and so part or all of the query can come from the current payload. By default, this query updates the most recently created Event in a “new” state.
  • Multiple Events By Query: You can create an advanced query to retrieve multiple Events. This query is templatable, and so part or all of the query can come from the current payload.

Data Method

The second step is selecting how you want to apply updates to the events selected by the query above. The Event: Update Node has three different options:

  • Individual Fields: You can input values for specific fields that can be filled in using individual string templates. In this case, none of the fields are required - leaving a field blank will just not update that field on the event.
  • Payload Path: This option will take path on the current payload that points to an event object and apply it’s values to the queried events as an update. The object will be validated against the Event Patch schema.
  • JSON Object: This option takes a JSON template string that can be parsed into a JSON object that validates against the Event Patch schema.

Event Tags

The “Individual Field” configuration also allows you to modify tags. You can add, change, and remove tags on the event while leaving other existing tags intact.

Update Device Node Tag Configuration

For removing tags, the configuration just takes a templatable tag key, and the tag that matches the given key is removed. In the example above, we are removing the tag reportsF from the event. If the tag key to remove is not found on the event being updated, the removal does nothing.

For modifying or adding a tag, the configuration takes both the key and the value (which are both templatable). If tags already exist on the event with the given key, its value is updated with the new value.

If more detailed control is needed for modifying tags, the “JSON Template” or “Payload Path” methods of entry should be used.

Result Path

You may store the result of the operation at a path on your payload.

In the case of a single event update, the result will be the updated event. In the case of a multiple event update, the result will be { "success": true }, indicating that the updates have been queued and will be applied shortly.

If the update errors, the result will be an object with an error property.

Node Example

For example, if we are querying for a singe event, to place on the path data.myEvent, the result will look like the following:

{
  "data": {
    "secondFloor": {
      "sourceName": "kevin@losant.com",
      "state": "new",
      "level": "critical",
      "id": "5d28eabf55297e000636aab8",
      "eventId": "5d28eabf55297e000636aab8",
      "updates": [
        {
          "sourceName": "Event Update Node: Startup Process",
          "comment": "Startup Process Initialized",
          "sourceId": "5d1a23e25d792a00068f44c1",
          "sourceType": "flow",
          "creationDate": "2019-07-12T22:17:00.441Z"
        }
      ],
      "message": "",
      "lastUpdated": "2019-07-19T13:15:24.075Z",
      "creationDate": "2019-07-12T20:17:03.424Z",
      "applicationId": "5d06d1bc4863a400066de8ed",
      "sourceId": "5b031db82f4fa100050fdf35",
      "sourceType": "user",
      "eventTags": {
      "floor": "second"
      },
      "subject": "Generator Created"
    }
  }
}

Node Errors

Given a response path of data.myEvent, a failed event query might look like:

{
  "data": {
    "myEvent": {
      "error": {
        "message": "hello is not a valid value for state",
        "type": "Validation"
      }
    },
    ...
  },
  ...
}

There are most common error that wil occur with this node are all around query validation. It is very easy to create an invalid query when using string templating.

For example, the above error would be returned if you tried to query for all Events with a state of hello (which is not a valid value for event state).

Was this page helpful?


Still looking for help? You can also search the Losant Forums or submit your question there.