This feature is available since midPoint 3.7.

MidPoint offers an easy way of starting a task that is similar to a pre-existing one. The pre-existing task is called a template, although it is technically an ordinary task: with an exception that it is not meant to be executed directly.

An example

This is a task template that sets a description for user userName to the value of userDescription. These two parameters are expected to be present as extension values in a task that is created from this template.

<task xmlns:s=""
    <name>Change description task template</name>
        <scext:executeScript xmlns:scext="">
                        <c:value xsi:type="c:ScriptExpressionEvaluatorType">
                                import com.evolveum.midpoint.xml.ns._public.common.common_3.*

                      'Modifying user {}', input)
                                def deltas = DeltaBuilder.deltaFor(UserType.class, prismContext)
                      'Change:\n{}', deltas.iterator().next().debugDump())
                                midpoint.executeChanges(deltas, null)
    <ownerRef oid="00000000-0000-0000-0000-000000000002"/>
    <executionStatus>waiting</executionStatus>      <!-- this is just a template, therefore it should not be executed -->
    <cleanupAfterCompletion>PT10M</cleanupAfterCompletion>  <!-- delete 10 minutes after completion -->

Note that executionStatus of this task is set to waiting, so that the task template itself will not be executed. The userName and userDescription extension items are not present: they are to be inserted into tasks created from this object. Finally, note the cleanupAfterCompletion: it says that tasks created from this template will be automatically deleted 10 minutes after their completion (i.e. switching into the CLOSED state).

Creation of a task from a template

Creation of a templated task is facilitated by two methods among midPoint functions:

midpoint.submitTaskFromTemplate(String templateTaskOid, List<Item<?, ?>> extensionItems)
midpoint.submitTaskFromTemplate(String templateTaskOid, Map<QName, Object> extensionValues)

The former method expects a list of prism items to be inserted into an extension of newly created task. The latter method is less general but easier to use: it expects a map of extension item name and its (real) value.

So, in our case the usage would look like this:

midpoint.submitTaskFromTemplate('79dacdf7-2bc9-4eef-9c63-08d53d2392c3', [
	(new QName('userName')):'jack', 
	(new QName('userDescription')):'new desc jack'

See also Variables in bulk actions for more information on using bulk actions with variables.

Task Cleanup

This method is likely to produce a lot of tasks that are relatively short-lived. There is a cleanup task in midPoint that deletes old closed tasks. However, the default setting may cause tasks to stay around for too long.

Therefore there is now a cleanupAfterCompletion task property that can be used for finer control over the cleanup. This property can be set explicitly to force task cleanup after a specific interval.

See Also