Hi,
I am back with my favorite messages.
I am trying to start processB from processA by startProcessInstanceByMessage(String messageName, String businessKey)link, because I want to set business key of processB.
When I try just the first parameter (messageName) the processB is started and no error is thrown, but when I try also the second parameter (businessKey) I get this exception:
The process could not be started. :
Cannot instantiate process definition Process_1:5:e1af2b32-0b2c-11e8-9ac4-605718bb85a1: Error while evaluating expression: ${ execution.getProcessEngineServices() .getRuntimeService() .startProcessInstanceByMessage(âMSG_START_1â,âbkOfSupportProcessâ)}. Cause: Cannot coerce from class java.lang.String to interface java.util.Map
This is how it looks like.
Could you please help me with this?
I do not want to start processB and set up some correlationId variable, I want to use the businessKey, which I think should be used for the situation like this.
I think there are multiple methods with the signature RuntimeService#startProcessInstanceByMessage(arg1, arg2) and the EL runtime is not particularly clever in choosing the right one (=> doesnât consider argument types). As workarounds, you can either implement a custom Spring or CDI bean that you call from the expression and that internally calls the correct Java API. Or your write the expression by using the message correlation builder API, via which you can express the same logic unambiguously.
Cheers,
Thorben
edit: Or implement the throwing event via a script or Java class.
Hi Thorben,
I have been waiting for your response I did the workaround using message correlation builder API in the meantime, but the thing is, that I can not set a process business key via the message correlation builder, or can I?
I also want from one process to send a message to start a new process (with a message start event). But I want to pass/map the variables from the first process into the second.
How can I do this with the MessageCorrelationBuilder?
Thanks
the exact line that you should be insterested in is .setVariable(âcorrelationIdâ,execution.getBusinessKey())
where the first parameter is variable name and the second is variable value
Thanks @lhofer87.
However, this will give me only the businesskey and not all variables, right?
I wrote the following:
Map<String, Object> vars = execution.getVariables();
MessageCorrelationResult res = execution.getProcessEngineServices().getRuntimeService().createMessageCorrelation(âaMessageNameâ).setVariables(vars).correlateWithResult();
If the message is correlated to a message start event then the given business key is set on the created process instance.
Thatâsthe case
So iâm expecting to start by message my process B and associate it a new business key
But the result is
Cannot instantiate process definition ProcessA Error while evaluating expression: ${execution.getProcessEngineServices().getRuntimeService().createMessageCorrelation(âmyMessageNameFromProcessBâ).processInstanceBusinessKey(âcreateThisBusinessKeyâ).correlateWithResult()}. Cause: org.camunda.bpm.engine.ScriptEvaluationException: Unable to evaluate script: ReferenceError: âcreateThisBusinessKeyâ is not defined in <eval> at line number 1
Hi Flo,
I think the only issue was the weird quotation marks wraping the createThisBusinessKey. So fix that and you will be fine.
Also, I have created some updated sample process for this, feel free to test it.
Glad to help you.
Cheers
Lukas
Hi Thank you so much!!
I tried your bpm and it works perfectly fine
But when i fix my Expression with yours (just changing the message name)
${execution.getProcessEngineServices().getRuntimeService().createMessageCorrelation(âmyMessageNameFromProcessBâ).setVariable(âcorrelationIdâ,execution.getProcessInstanceId()).processInstanceBusinessKey(âHi! I am your business key :)â).correlate()}.
i get
Unable to evaluate script: <eval>:1:2 Expected ; but found ! Hi! I am your business key ^ in <eval> at line number 1 at column number 2
changing the business key to another value changes nothing
processInstanceBusinessKey(âjohndoeâ)
Unable to evaluate script: ReferenceError: âjohndoeâ is not defined in <eval> at line number 1
i could take your bpm and adapt but iâd like to understand why it failed
Sorry âŚ
So,
it is a littbe bit hard for me to explain this, but I think the following happens:
you create a message correlation (everything is fine here)
process will sucessfully correlate and start a new process
because there is no transaction boudaries the process fails on the next activity (a service task with input parameter) and the error is not really transparent about what happened
the service task has one input parameter in a javascript:"${execution.processBusinessKey}" what this does is that the engine grab processBusinessKey and wrap it between the â${}â which will make a request for property with same name as a processBusinessKey, which will fire an error about undefined âvalue in business keyâ
I have changed the script to this java.lang.System.out.println("BK IS: " + execution.processBusinessKey); and everything works flawlessly
here is the dia: whatiswrong.bpmn (17.9 KB)
PS: if you want the previous version to be working, just create another variable in the correlation with the same name as the businessKey value so the request would look like this: ${execution.getProcessEngineServices().getRuntimeService().createMessageCorrelation("hereComeANewChallenger").setVariable("correlationId",execution.getProcessInstanceId()).setVariable("johndoe",execution.getProcessInstanceId()).processInstanceBusinessKey("johndoe").correlate()}
But I think this is wrong approach.
EDIT: I forgot the async after on the âstart at receiveâ so if you will be working on that diagram, uncheck it so you see any potential errors.
Cheers
Lukas
How did you implement this? Was it as end listener in javascript or an expression or what?. I cannot get this to work trying all sorts of different approaches.
I have the same use case as you where I am initiating a second workflow with message correlation and want to pass all the process variables from the first process into the second process.
Appreciate any help you or anyone else could offer.
By the way, using this mechanism fails if a second message passes through the message send event expression, which is my use case. The error is the following:
${execution.getProcessEngineServices().getRuntimeService().createMessageCorrelation(ânotificationsWorkflow1â).processInstanceBusinessKey(â789â).correlate()}. Cause: java.lang.ClassCastException: [Ljava.lang.String; cannot be cast to jdk.nashorn.internal.runtime.ScriptObject