Custom filters in Camunda Tasklist

Camunda Tasklist allows you to create filters allowing you to group tasks based on specific criteria. For example you could create a filter for ‘Expense Approvals that are older than 5 days’ or ‘Any task that is assigned to me’. Whilst there are numerous options when creating filters via the UI it has one specific gap: creating filters based on Process Variables. Here is how you can accomplish this via code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

@Component
public class FilterBuilder {

@Autowired
TaskService taskService;

@Autowired
FilterService filterService;

@Autowired
AuthorizationService authorizationService;

@EventListener(ApplicationReadyEvent.class)
public void createCustomFilter() {

TaskQuery myTasksQuery = taskService.createTaskQuery()
.processVariableValueEquals("MyCustomKey","Custom");

Filter myTasksFilter = createFilter("My Custom Tasks", myTasksQuery);

}

private Filter createFilter(String filterName, TaskQuery myTasksQuery) {
Filter myTasksFilter = filterService.newTaskFilter(filterName);
myTasksFilter.setOwner("mcbcam");
myTasksFilter.setQuery(myTasksQuery);
filterService.saveFilter(myTasksFilter);
return myTasksFilter;
}
}

In your Camunda project create a new Component. Add a method to create your custom filter and decorate it with the ‘ApplicationReadyEvent’ Event Listener. This will trigger your code once the SpringBoot application has fully started and all the dependencies are available for injection.

Start by describing the filter’s criteria. Here I am selecting for processes where the ‘MyCustomKey’ Process Variable has the value of ‘Custom’.

For a full list of options to create a filter see the TaskQuery documentation.

Then use the resulting TaskQuery object to create a new Task Filter.

At this point you will have a new filter displayed in your Tasklist.

What if you want to do this for everyone though? This can be done by creating a new Authorization for the filer that gives everyone Read permissions. Here’s the code…

1
2
3
4
5
6
7
8
9
10
11
12

private void configureSecurity(Filter filter) {
var authorization = authorizationService.createNewAuthorization(Authorization.AUTH_TYPE_GLOBAL);

authorization.setUserId(Authorization.ANY);
authorization.setResource(Resources.FILTER);
authorization.addPermission(Permissions.READ);
authorization.setResourceId(filter.getId());

authorizationService.saveAuthorization(authorization);
}

There you have it. Custom filters based on Process Variables.

  • Copyright: Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
  • Copyrights © 2015-2024 Nick Mckenzie

请我喝杯咖啡吧~

支付宝
微信