cancel
Showing results for 
Search instead for 
Did you mean: 

retrieve workflow instance from task id

vale_arna84
Champ in-the-making
Champ in-the-making
Hello,

Is there a way to retrieve a workflow instance from a task id using javascript apis? I would like to add some notes to a document shared by a series of review and approve tasks. For now I'm getting the tasks related to a logged user with a workflow.getAssignedTasks(), but I don't know how to retrieve the workflow instance. I'm planning to add a "note" variable to the workflow. Is there a better way to create and access a text variable related to a workflow content?

Thanks

Valerio
2 REPLIES 2

sgartner
Champ on-the-rise
Champ on-the-rise
Is there a way to retrieve a workflow instance from a task id using javascript apis? I would like to add some notes to a document shared by a series of review and approve tasks. For now I'm getting the tasks related to a logged user with a workflow.getAssignedTasks(), but I don't know how to retrieve the workflow instance. I'm planning to add a "note" variable to the workflow. Is there a better way to create and access a text variable related to a workflow content?

Valerio,

I'm not sure what you mean by "shared by a series of review and approve tasks".  Do you mean you have many workflows running against the same document?  Also, you talk about adding notes to a document and you also talk about adding a "note" to the workflow, so I'm not sure which you want to do.  I'll assume the former.

You can get the package (and from there the doc) from the task id this way:

var taskId = args["taskId"];
var task = workflow.getTaskById(taskId);
// Assuming there is only one document,
// if you have more you'll need a loop…
var theDocument = task.getPackageResources()[0];

jucanet
Champ in-the-making
Champ in-the-making
var tarea = new Array();
var i = 0;
for each (task in workflow.assignedTasks){
   tarea = new Array();
   tarea["id"] = task.id;
   tarea["type"] = task.type;
   tarea["name"] = task.name;
   tarea["description"] = task.description;
   tarea["created"] = task.created;
   tarea["startDate"] = task.startDate;
   tarea["dueDate"] = task.dueDate;
   tarea["priority"] = task.priority;
   tarea["percentComplete"] = task.percentComplete;
   tarea["status"] = task.status;
   tarea["isCompleted"] = task.isCompleted;
   tarea["asignada"] = "Si";
   tarea["wf_id"] = get_wf_id(task.id);
   i++;
}

for each (task in workflow.getPooledTasks("usuario_r2")){
   tarea = new Array();
   tarea["id"] = task.id;
   tarea["type"] = task.type;
   tarea["name"] = task.name;
   tarea["description"] = task.description;
   tarea["created"] = task.created;
   tarea["startDate"] = task.startDate;
   tarea["dueDate"] = task.dueDate;
   tarea["priority"] = task.priority;
   tarea["percentComplete"] = task.percentComplete;
   tarea["status"] = task.status;
   tarea["isCompleted"] = task.isCompleted;
   tarea["asignada"] = "No";
   tarea["wf_id"] = get_wf_id(task.id);
   i++;
}

model.tareas = tarea;

function get_wf_id( taskid ){
   var taskparam = taskid;
   var docNodeRef = workflow.getTaskById(taskparam).getPackageResources()[0].nodeRef;
   var theDocument = search.findNode(docNodeRef);
   for each (wf in theDocument.activeWorkflows) {
      var path = wf.paths[wf.paths.length-1];
      for each (task in path.tasks) {
         var tareaIN = new String(task.id);
         var tareaFOR = new String(taskparam);
         logger.log("task ->"  + tareaIN.replace("$","")  + "<- comparando con: ->" + tareaFOR.replace("$","") + "<-") ;
         if (tareaIN.replace("$","")  == tareaFOR.replace("$","")){
            return wf.id;
         }
      }
   }
   return 0;
}