Issue with sending a message via sendMessage in a Groovy script

1
0
-1

Hello community,

I'm facing an issue while using the `sendMessage` function in a Groovy script to send a message to a Bonita BPM process. But the message doesn't seem to be processed correctly. I would like to mention that I am a beginner in Bonita. I have already taken a look at the documentation, but I am currently stuck.

Here's a simplified example of the script I'm using:

import org.bonitasoft.engine.api.APIAccessor
import org.bonitasoft.engine.api.ProcessAPI
import org.bonitasoft.engine.expression.ExpressionBuilder

// Retrieving the Process API
ProcessAPI processAPI = apiAccessor.getProcessAPI()

// Defining the expression for the target process
Expression targetProcess = new ExpressionBuilder()
.createConstantStringExpression("MyTargetProcess")

// Defining the expression for the target flow node
Expression targetFlowNode = new ExpressionBuilder()
.createConstantStringExpression("MyTargetTask")

// Creating the data map to send with the message
Map mapData = new HashMap<>()
mapData.put("key1", "value1")
mapData.put("key2", "value2")

// Sending the message

def messageId = processAPI.sendMessage("MyMessage", targetProcess, targetFlowNode, mapData)

if (messageId != null) {
logger.info("The message has been sent successfully.. ID du message : $messageId")
} else {
logger.warn("Message sending failed. The value of the sent message is null.")
}

The target process (MyTargetProcess) and the target task (MyTargetTask) do exist and the case of the process and task names in the script (MyTargetProcess and MyTargetTask) matches the actual case. The message isn't correctly processed by the target process. I've checked the logs, but I can't find the root cause of the problem (no errors). If I add logs, I am able to retrieve targetProcess, targetFlowNode, and mapData, but the final message (processAPI.sendMessage("MyMessage", targetProcess, targetFlowNode, mapData)) is null.

Could someone help me identify what might be wrong with my approach or provide guidance on the correct way to send a message in Bonita BPM with a Groovy script?

Thanks in advance for your assistance!

1 answer

1
0
-1

Hi l.simonet,

Have you tried using a throw message event?

I think maybe it can be easier to achieve what you're trying to: you throw a message with a value you have defined there and you catch it on another process and you retrieve that value. You would simply need to configure on your throw message event your target process and element and the content of your message.

On the diagram side, it would be more explicit like this:

Hope this helps,

- Thalía

Notifications