updating a task variable … in another task of the current workflow

Posted: 30 November 2009 in CSSDK, Java, OpenDeploy, Teamsite, URLExternalTask, Worfklow models, Workflows

Sometimes, you want to change things in another task before you get to that task. for example, to set the name of the instance of a deployment task.

First, you have to be able to find the other task. For this, you need its name and add call the following method:

 * find a task by name in a workflow job
 * @param job the job to get the task from. use task.getWorkflow() from the current task
 * @param taskName the name of the task to find in the workflow
 * @return the task object found, or null if an exception occured or the task was not found in the workflow
 public static CSTask getWorkflowTask(CSWorkflow job, String taskName) {
 CSTask taskFound = null;
 try {
 for (CSTask task : job.getTasks()) {
 if (task.getName().equals(taskName)) {
 taskFound = task;
 } catch (CSException ex) {
 Logger.getLogger(TaskUtil.class.getName()).log(Level.SEVERE, null, ex);
 return (taskFound);

Then, you can add the follwoing code to update the variable of the target task:

public static void setTargetTaskVariable(CSExternalTask task, String targetTaskVariableValue) throws CSException {
 String targetWorkflowTask = task.getVariable("targetWorkflowTask");
 String targetTaskVariableNameToSet = task.getVariable("targetTaskVariableNameToSet");
 CSTask workflowTargetTask = TaskUtil.getWorkflowTask(task.getWorkflow(), targetWorkflowTask);

 if (workflowTargetTask != null && targetTaskVariableNameToSet != null && targetTaskVariableValue != null) {
 //System.out.println("open deploy task found. Updating variable.");
 workflowTargetTask.setVariable(targetTaskVariableNameToSet, targetTaskVariableValue);
 System.out.println("Setting variable: " + targetTaskVariableNameToSet + "=" + targetTaskVariableValue);
 } else {
 if (workflowTargetTask == null) {
 System.err.println("Target task not found.");

 } else if (targetTaskVariableNameToSet == null) {
 System.err.println("Target task variable name not set.");

 } else if (targetTaskVariableValue == null) {
 System.err.println("Target task variable value not set.");



Add a couple of task variable to the updating task, namely

  • targetWorkflowTask
  • targetTaskVariableNameToSet

Your class must calculate the value of the variable to set and update the variable whose name was passed to the workflow, in the specified task. I have used this to set the instance name of the deployment to the job id of the workflow, making them unique.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s