Schedule a process Instance to start at a particular date and time as specified in the Custom UI form

Hi,

My current implementation is that in my Custom Application, I have an Add Document page, On click of a button, I send some process variables along with the start process REST API call.

What I need to achieve now is that depending on a variable defined in the Add Document page, I need to schedule a timer. I think Timer event would be used in such situation but I am unable to understand the implementation. Also, as I said that I send some process variables while starting the process Instance, so the question is

  1. How to implement the timer event in away that it gets scheduled as per the Schedule date as specified in my start page?
  2. Even if the process instance gets triggered by the timer event , how will I send the process variables to be used along the bpmn flow while starting the process?

Please help me understand if this is achievable and how in detail if possible?

Something like this might work:
https://cawemo.com/shares/65b16c5a-7c86-415a-8f68-403542c002b8

Currently I start any process instance on button click on the Add document page So, I need to do two things now -

  1. Start on button click.
  2. Start as per schedule.
    My current diagram looks something like this

In this, there is no reference of the Add Document page. It is a separate form in my Custom application. So if I change my bpmn and make the Add document task a user task after the start process event then when would the start process event be called ?

Also, how do I send the process variables automatically, which as per now I was send in Rest API calls to Camunda application?

I’ve updated the model so that your document page could have 2 options - depending on the data send in the start process request it will either wait or start it immediately.

Can you explain what you mean when you ask about sending variables?
If you send variables with a REST call they will automatically be persisted by camunda. what are you trying to achieve?

Ok. So just to be clear -
I have 2 buttons -

  1. To start process instance immediately(I send some process variables here).
  2. Schedule start process(Should I send the same process variables here? and they will be persisted across BPMN whenever the process starts as per the timer?).

By what you suggest, I should call the start event using REST API at both the calls. Then have an Exclusive gateway which will make s decision. If the the decision is to start the process immediately, then I use the message event to start immediately. If the decision is to wait for the timer then it will start as scheduled?
Also the process variables will be sent in both the REST calls while starting the process right?

Please correct me if I am wrong.

Correct - in both cases the variables can be send along to start the new process, this can be done using Rest or Java

Ok. Thank you. Let me try this and I will reach out if I face any issues.

Can I use the second Exclusive gateway like this?Without any conditions will it execute? or shall I use the inclusive gateway in place of the second exclusive gateway?

The second gateway is a Merging gateway - it simply turns 2 sequence flows into one and does not need any execution semantics. It’s just good modeling practice to have these gateways.

Ok Thanks. Then I will make this as an Exclusive Gateway without any conditions.

Hi,
I applied your suggested approach and it is working as expected.
The only problem that I am suffering with Timer is that I give a time in the format 2017-07-22T10:46:00.000 and I am in the IST time zone So it is expected to start at that exact time but sometimes it starts on time while other times it starts after a delay of about 40-50 seconds from the time it is scheduled to work on.

I am not sure why there is some delay in the initiation. Is this normal or is there something wrong?

That is expected behavior and it depends on the frequency of the job executor which will pick up all timer jobs and execute them.

You can always change the job executor settings if you need more accurate timer events.

Oh. Thanks a lot for your help. Your insight and instant response helped me a lot to solve my issues. Currently, starting the process on an exact time is not our major requirement, So having a little delay would not hurt.

I also wanted to have a clarity on Bulk operations that can be performed by Camunda Rest API. What I mean by this is if I have several documents to approve and with each approval there is a rest call associated to complete a user task in a process instance. So what happens if I try to approve them all. As I understand the Rest calls will be called in a sequential manner for all the associated process instances. Please correct me if I am wrong. Is it possible that I make all the Rest calls in parallel? I mean all the approvals get happen at the same instant or will it always be in a sequential manner like in a normal for loop.

Each process instance is single threaded so - If you wanted to send 4 rest calls to the complete tasks in the same instance they would be treated sequentially, this is a fundamental part of the engine’s design.

But if you had 4 rest calls going to different process instances then they would be run in parallel by the engine.

There is another option for doing things in bulk for a specific instance and that is by using Camunda’s Batch Operations, this can move X number of tokens at once - synchronously or asynchronously.

Hi Niall,

Thank you for your response. We may not be able to use Cockpit for the Camunda Bulk operations. But I would like to discuss my approach here. What if I select number of jobs(with their independent process instances) , get the user tasks associated with them that needs to be completed, add them to a list and on click of complete, run a parallel for-each loop.
I understand that the process-engine can run them in parallel but is there any way by which I can send them in parallel to the process engine? I mean like there is a REST API post call to delete all the process for history at once, is there any similar REST API call in which I could append all the tasks and complete them at once?