views:

321

answers:

2

I have an Alfresco document reference; what I'm looking for is a way to access workflow attached to that document and finish it (or progress it to the next transition) through Javascript.

Almost every example on the web shows how to start workflow, and from the dashlet I could call task command processor (/alfresco/command/task/end/[/transition]) if I knew the task ID, but how do I do the same thing from server-side web script starting only from the document reference?

There must be a way to access workflows from document and manage them programatically.

A: 

Well, I still don't know how to transition, but there are a couple of things I found out.

First, I can access workflows document participates in and cancel it:

for each (workflow in document.activeWorkflows) {
    workflow.cancel();
}

However, I'm still not quite sure how to progress tasks. I can get to the task and do something with it:

var task = workflow.getTask(taskId);
task.endTask(transitionId);

...but I still have no idea how to get to taskId or transitionId, either programmatically or through Alfresco.

Domchi
+1  A: 

From a document nodeRef you can signal the current task like this:

var docNodeRef = "workspace://SpacesStore/<GUID HERE>";
var transitionId = "some action";
var theDocument = search.findNode(docNodeRef);
foreach  (currWorkflow in theDocument.activeWorkflows)
{
    var path = currWorkflow.paths[currWorkflow.paths.length-1];
    var task = path.tasks[0];
    for (var transitionKey in task.transitions)
    {
        if (task.transitions[transitionKey] == transitionId)
        {
            path.signal(transitionId);
            break;
        }
    }
}

If you want to signal the default transition you can skip the inner loop and just do this:

var docNodeRef = "workspace://SpacesStore/<GUID HERE>";
var transitionId = "some action";
var theDocument = search.findNode(docNodeRef);
foreach  (currWorkflow in theDocument.activeWorkflows)
{
    var path = currWorkflow.paths[currWorkflow.paths.length-1];
    var task = path.tasks[0];
    // Signal default transition
    path.signal(null);
}
Scott Gartner