This operation links a received message to a process instance. Use it when an external message payload should be delivered to a process instance that is waiting for a BPMN message.
The base request is:
receive()
The following example delivers a message to a waiting process instance:
new RuntimeProcessInstanceService().receive({
name: variables.messageName,
correlationKey: variables.businessKey
});
You can use the optional ReceiveMessagePayload schema when a script needs to deliver a BPMN message to a waiting process instance.
The following example sends an updateStatus message and passes a status variable to the process instance:
const receiveMessagePayload = {
name: 'updateStatus',
correlationKey: variables.businessKey,
variables: {
status: 'SHIPPED'
}
};
new RuntimeProcessInstanceService().receive(receiveMessagePayload);
In this example, name: 'updateStatus' specifies the BPMN message to deliver and correlationKey: variables.businessKey identifies the process instance that should receive the message. variables contains data that is passed to the process instance when the message is received, which in this case is status: 'SHIPPED' that provides a process variable that can be used by subsequent process activities.
When the runtime finds a process instance waiting for the specified message and correlation key, the message is delivered and the process instance continues execution.