Due Date and Follow up Date for the whole Process Instance

Hi Team!

Is possible to assign a Due Date and Follow up Date that is consistent across all tasks within a process-instance and not individually per task?

Our goal is to reflect this set Due Date and Follow up Date in this section of the UI, consistent for all tasks within the process instance.

image

Thank you!

@hassang

Hey @edcapulong ,

You could for example use an expression ${duedate} for defining the due dates of the task. Once you set the variable duedate the expression resolves to the value of the variable so it should be the same for all task. Same can be done for the follow up date.

I hope that helps
Kind regards
Nele

Hi @Nele !

Thank you for the response, I was just wondering though if I will continuously get the same remaining time for the set “due date” even if I’m not yet on the other task.

For example, let’s say I did set a variable which contains the value “${dateTime().plusDays(60).toDate()}” to set a due date of 60-days for the whole process-instance and I only have 2 user tasks (task1 and task2).

When I’m on task1, the timer for the due date will now kick in, let’s say I stayed on task1 for 3 days, when I complete task1, and proceed to task2, I should see a due date “in 57 days” on task2. Meaning there is continuity in terms of the remaining time for due date.

Is this the case?

Thanks!

Hey @edcapulong,

thanks for explaining. If you do it like described the due date for the second task will start again with 60 days. I think that is the problem you encounter currently.

In order to have a fixed date for the overall process instance you could use a Listener at the start of your process (for example after the start event) that calculates the fixed due date for each instances. You can use a Delegate or Script to calculate it.

If you save than the fixed due date to a variable and give it back to the process context you can then use an expression to access the value. Then the date will be the same for all user tasks and won’t depend on the creation of the user tasks but on the creation of the process instances.

I hope this solves your problem.
Nele

Hi @Nele ,

Thank you for the response, when you say a listener are you referring to the “Execution Listener” portion of a start event? If I choose, “Script” what language does it accept? Does the engine accepts Python? What should I place on the “Format” field?

On the “Field Injection” portion, can you please provide a brief summary for its usage? what should I place here? Is this the area where I create a new variable and place a value to it?

Thanks!

or are we looking at placing a service or script task after the start event?

Hey @edcapulong,

Yes I meant an execution listener after a start event. Execution listener are used to include code snippets that are not main part of the business logic. So I think in your case it would make sense to use a listener instead of a Service or Script task.

If you want to implement a Listener you can basically choose between Script or a Java Delegate.

If you choose Script you could use Python but you would need to add a dependency to the Pom file so the engine would be able to execute it.

The Camunda Engine itself offers you to use Groovy or JavaScript out of the box.

You have to set the language in the field Format and if you want to go for inline Script you can type the Script in the field. Note: It is recommend to use an External Resource to store your script. Otherwise it will be saved to the BPMN.XML directly. This will make the maintenance harder.

You can find more information about Script Languages in our docs.

You can use JavaScript to define the date and then you have to make sure you set the variable back to the execution in your Script:

execution.setVariable(variablename, value)

I hope this helps
Nele

Hi @Nele ,

Thank you so much for the response, I have another question related to the behavior of these listeners assigned to an event or a task. Let me know if my assumptions are correct:

  1. For execution listeners - the java class will only run at the “start” and “end” of an event. Since you get to choose the “Event type” which tells Camunda when to run the class. So in a way it’s triggered based on the event type and not always running.

  2. For task listeners - same concept with execution listeners, basically triggered if and when the set “Event type” is for the listener is met.

My question is how can I ensure that each task in my process-instance gets the same remaining days for a due date even if the user isn’t yet on that particular task?

Does this mean that I have to apply the same listener for all my tasks to have the same updated remaining days for the due date?

Thanks! I hope I related my thoughts clearly. Let me know if something is not clear.

Here’s the code I’m working on btw.

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.*;

public class Main {

public static void main (String[] args) {
	
	/*Date Parser*/
	
	/*DateTimeFormatter myDateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");*/
	DateTimeFormatter myDateFormatter = DateTimeFormatter.ISO_LOCAL_DATE;
	
	/*Get, format and Print current system time*/
	
	LocalDate currDate = LocalDate.now();
	System.out.println("Current Date: " + currDate);
	
	/*Dummy Alert_Date String, in the real code you delegateExecution.getVariable("alert_Date")*/
	
	String alertDate = "2022-02-23";
	
	/*Parse alert_Date String to Date*/
	
	LocalDate newAlertDate = LocalDate.parse(alertDate, myDateFormatter);
	System.out.println("Alert Date: " + newAlertDate);
	
	/*Calculate the due date*/
	
	LocalDate dueDate = newAlertDate.plusDays(60);
	System.out.println("Due Date is on: " + dueDate);
	
	/*Calculate the remaining days*/
	
	long remainingDays = currDate.until(dueDate, ChronoUnit.DAYS);
	System.out.println("Remaining Days until due: " + remainingDays + " days");
	
	/*delegateExecution.setVariable("remainingDays", remainingDays)
	 * Reflect this then on the Due Date field under User Assignment task
	 * */
	
}

}

OR rather, what I should goal for is pass the same date on the “Due Date” field, rather that calculating the remaining time since Camunda already does it for me.

I think I’m overthinking a bit.

@Nele

Hey @edcapulong ,

Execution Listeners can go on all BPMN events and are triggered at the start or end of the execution of the BPMN element as you explained. Task Listeners are used for User Tasks and are attached to the Task Life cycle of BPMN.

For your case, you can use an Execution Listener after the start event. This listener will calculate the due date for you. You set the due date as a variable to the process context.

then you can use an expression in all your user tasks to access the value #{duedate}. So no need to calculate the remaining time for every single user task.

I hope this helps
Nele

1 Like