You can create a task that automatically executes upon completion of another task—a process called task chaining. Task chaining can help you avoid duplicating work when you have a task that already accomplishes part of what you need your task to do. You can chain a task that does the remaining work to an existing task. For example, suppose you need a task that creates a user and assigns the user to an organizational unit. iManager includes the Create User task for creating users. You can create a task that assigns a user to an organizational unit and chain it to the Creat User task.
To chain tasks you need to
Add code to the initial task to pass objects to the chained task.
Add code to the chained task to get objects from the initial task.
Include an entry for the chained task in a registration file using the <chained-task> element.
To pass objects from the initial task, you need to call com.novell.nps.gadgetManager.JobData.put(Object key, Object value) or com.novell.nps.gadgetManager.JobData.setObjectNames(String[] names) in the first task in the chain. For example:
import com.novell.nps.gadgetManager.JobData; JobData data = JobData.getJobData(this); if (null != data) { data.put(ANYKey, anyValue); }
The Create User task provided by iManager is already enabled for serving as the initial task in a task chain. The name of the User object created is set using the following code:
JobData data = JobData.getJobData(this); if (null != data) { data.setObjectNames(new String[]{targetOE.getFullName()}); }
To get an object reference from the initial task, call com.novell.nps.gadgetManager.JobData.getJobData(GadgetInstance gadget):
JobData data = JobData.getJobData(this); if (null != data) { String [] objNames = data.getObjectNames(); }
Use the <chained-task> element to define the chained task in a registration file:
<plugin> <chained-task> <id>moduleId.ChainedTaskId</id> <chaining-initial-task-id>base.CreateUser</chaining-initial-task-id> <order>300</order> ... (Everything else your task needs, just like a normal task, <class-name>, <display-name>, etc.) </chained-task> </plugin>
The <chained-task> element is identical to the <task> element, except that it allows for an additional child element, <chaining-initial-task-id>, which is the element you use to specify the task that the chained task will follow. The <order> element specifies the order of appearance of tasks in a role.