How to invoke a Flow when inserted into an Entity?
In this tutorial, we are going to see how to process the notifications generated by the system when an ontology receives insertion messages.
Let's start from the "noderedTest" ontology that has the following structure:
We are going to create a flow that allows us to insert a value and register a notifier in order to process the information regarding the Insertion event in said ontology.
Let's assume the following insert flow:
Every time you click on the INJECT "Data to insert" node, an ontology instance will be inserted into "noderedTest". In order to collect the value of the insertion, you will use the "OnesaitPlatform Notification endpoint" node:
This node requires the following properties:
Name: (optional) The name that you will give to the node within the flow.
Ontologies available: Drop-down where you will select the ontology on which you want to receive notifications.
Operation type: It is the type of operation that you will be waiting for to be notified. You have three options:
INSERT: You will be notified of a message for each insertion operation on the ontology.
REMOVE: You will be notified of a message for each delete operation on the ontology.
UPDATE: You will be notified of a message for each update operation on the ontology.
URL: Name that you will give to the endpoint that listens for the notification that the platform will return. As a limitation, there cannot be two identical URLs within a domain.
Continuing with the example, let's configure the node to notify you with any insertion message about the "noderedTest" ontology:
To test it, launch an insert by clicking on the "Data to insert" INJECT nodem and check the "debug" tab:
The first data that appears in the "debug" log is the response to the insertion, showing the ID of the element inserted in the ontology.
Just below it, you can see the message received by the notifier. In the "msg.payload", you will receive an object with the following structure:
The meaning of each field is as follows:
notificationModel: object that includes all the information of both the notification and the operation. Within the "notificationModel", there is:
operationModel: object that includes all the information regarding the operation for which you have been notified. The information of the operation is broken down into:
ontologyName: name of the ontology that has been the object of the operation.
operationType: type of operation performed on the ontology.
user: user who performed the operation.
source: module from which the operation was launched.
body: contains the data of the operation. In this case, it is the inserted record.
queryType: in the case of a query operation, the type of query.
objectId: in the case of an operation by ID, the ID of the ontology object that was affected by the operation.
deviceTemplate: type of device that launched the operation. It will only be informed if the operation was launched from a device defined in the platform.
device: name of the device that launched the operation. It will only be informed if the operation was launched from a device defined in the platform.
clientSession: client session.
clientConnection: client connection.
cacheable: only applies to queries, to indicate whether they have been retrieved from cache.
notificationEntityId: identificador nodered del nodo que recibe la notificación.
url: endpoint mediante el cual llega la notificación al nodo.
Si quieres ver al dato de la operación, accede a "msg.payload.notificationModel.operationModel.body"