Executing a process with result but also get processInstanceKey before the instance completes

I extensively use Zeebe processes who’s result (variables) I await in my C# application using the C# zbclient library.
Thus I mainly use the “.WithResult” option during creation of the process instance. However I also need to monitor incidents programmatically (for example by using the Operate API), which I seemingly cannot do, since I don’t find any option to retrieve the “processInstanceKey” when I use the “.WithResult” option, which I need to find the correct instance out of multiple ones running with the same process definition.

The “other way around” also doesn’t seem to work (not using “.WithResult” but then getting notified when the instance completes immediately, along with the process variables).

The only hack I could think of is injecting a “dummy” service task at the start of each workflow which will call a handler in backend, since job handlers have access to the processInstanceKey, but this will negatively affect latency which is already a bit problematic.

I’d also be fine with unresolved incidents causing Exceptions in the task I’m awaiting, but it doesn’t seem like the library supports this. So far it seems that tasks with incidents just don’t complete (or only complete when the timeout has exceeded).

Is there any way to achieve this? Am I missing something?

In theory, .WithResult will force the C8 system into a “Synchronous” mode. When the process is completed, it sends its results back to the caller…

Without “WithResult” the system thinks you’re working in a typical asynchronous mode, so you will need to the PIID to poll for the status (or have the process fire a callback with its PIID as it completes). However, I don’t see an entry in the gRPC to ask the cluster the current state of a process based on the PIID.

But according to Zeebe API (gRPC) | Camunda 8 Docs the CreateProcessInstanceWithResult gRPC call should return the PIID. Which suggests an error in the C# client.
The C# Client from Camunda Community Hub seems to suggest that the PIID (ProcessInstanceKey) is available, but I don’t read enough C# to be able to tell you how to access it.

Thanks for the reply. I do get the IProcessInstanceResult you linked back but only when the process instance finishes successfully. However I need the ID before the instance finishes, so I can use it to look (or poll) for incidents programmatically.

If I look at the raw gRPC interface it doesn’t really seem possible either. All of the methods listed there are available as described with the C# client.

I basically need get notified of (unresolved) incidents within a few seconds of them happening while still using “WithResult”.

Hi @JJWolf,

This is not possible, as the CreateProcessInstanceWithResult RPC assumes, that no incident has happened (or will be resolved during the timeout for the call, which is just a theoretical option).

There is an option with asynchronous programming to follow the progress of a process instance until a certain activity or event is reached: camunda-8-examples/synchronous-response-springboot at main · camunda-community-hub/camunda-8-examples · GitHub. Maybe you can query for incidents, if this state hasn’t been reached in the expected timeout?

Hope this helps, Ingo

It wouldn’t be quite intuitive for the one designing the processes, but I could modify the XML programmatically of the deployed instances by either doing what you describe, or by putting everything in an expanded subprocess before I deploy the instance where I can put error boundary events by also modifying the XML.

It’s not elegant, since Operate would show different workflows than designed but it seems like I have no other option. In a fully automated environment where C8 is used for microservice orchestration purposes I’m surprised no one else has found this to be missing. Well it is what it is.

Thank you for your help.

But here’s the thing… Most systems don’t support streaming responses. You need to keep it to one call - one response. What you are asking for here is one call - two responses.

If you need the ProcessInstance ID to poll for instances, skip the “with result” and set up a callback point for the Process to tell you what the results are when it’s done.

It seems even getting process instance id to pass back in a separate call isn’t readily available without creating a job worker to call and get this value. Execution properties arent available like they are in Camunda 7, right? I’m hoping im wrong or missing something.

The OP wasn’t having issues getting the “CreateProcessInstance” → “ProcessID” portion working.
The expected response to “Create Process Instance” (with or without the results) includes the process instance ID according to the gRPC reference

I’m not 100% sure what you’re looking for in terms of Execution Properties, but C8 is a fully external worker model. You cannot directly access the JobExecutor in the same way that happens in C7. But that’s really not on topic for this thread.

I’m not sure how I implied there was an issue with that “CreateProcessInstance” call? I understand that would provide the value back in response. Didn’t OP say that using “WithResult” was the issue, that id isn’t available till it ends, yet OP wants it while process is still active? In my case, we are starting a process via a start message event passed via service bus. So there is no response available to the system that posted that message. We want to be able to send a message back containing the processInstanceKey, but not seeing an existing direct way to get the value to include it in the message.