Question

I'm trying to get a list of workflows the document is attached to in an Alfresco webscript, but I am kind of stuck.

My original problem is that I have a list of files, and the current user may have workflows assigned to him with these documents. So, now I want to create a webscript that will look in a folder, take all the documents there, and assemble a list of documents together with task references, if there are any for the current user.

I know about the "workflow" object that gives me the list of workflows for the current user, but this is not a solution for my problem.

So, can I get a list of workflows a specific document is attached to?

Was it helpful?

Solution

Well, for future reference, I've found a way to get all the active workflows on a document from javascript:

var nodeR = search.findNode('workspace://SpacesStore/'+doc.nodeRef);
    for each ( wf in nodeR.activeWorkflows )
    { 
        // Do whatever here.
    }

OTHER TIPS

I used packageContains association to find workflows for document. Below i posted code in Alfresco JavaScript for active workflows (as zladuric answered) and also for all workflows:

/*global search, logger, workflow*/
var getWorkflowsForDocument, getActiveWorkflowsForDocument;

getWorkflowsForDocument = function () {
    "use strict";
    var doc, parentAssocs, packages, packagesLen, i, pack, props, workflowId, instance, isActive;
    //
    doc = search.findNode("workspace://SpacesStore/8847ea95-108d-4e08-90ab-34114e7b3977");
    parentAssocs = doc.getParentAssocs();
    packages = parentAssocs["{http://www.alfresco.org/model/bpm/1.0}packageContains"];
    //
    if (packages) {
        packagesLen = packages.length;
        //
        for (i = 0; i < packagesLen; i += 1) {
            pack = packages[i];
            props = pack.getProperties();
            workflowId = props["{http://www.alfresco.org/model/bpm/1.0}workflowInstanceId"];
            instance = workflow.getInstance(workflowId);
            /* instance is org.alfresco.repo.workflow.jscript.JscriptWorkflowInstance */
            isActive = instance.isActive();
            logger.log(" + instance: " + workflowId + " (active: " + isActive + ")");
        }
    }
};

getActiveWorkflowsForDocument = function () {
    "use strict";
    var doc, activeWorkflows, activeWorkflowsLen, i, instance;
    //
    doc = search.findNode("workspace://SpacesStore/8847ea95-108d-4e08-90ab-34114e7b3977");
    activeWorkflows = doc.activeWorkflows;
    activeWorkflowsLen = activeWorkflows.length;
    for (i = 0; i < activeWorkflowsLen; i += 1) {
        instance = activeWorkflows[i];
        /* instance is org.alfresco.repo.workflow.jscript.JscriptWorkflowInstance */
        logger.log(" - instance: " + instance.getId() + " (active: " + instance.isActive() + ")");
    }
}


getWorkflowsForDocument();
getActiveWorkflowsForDocument();

Unfortunately the javascript API doesn't expose all the workflow functions. It look like getting the list of workflow instances that are attached to a document only works in Java (or Java backed webscripts).

List<WorkflowInstance> workflows = workflowService.getWorkflowsForContent(node.getNodeRef(), true);

A usage of this can be found in the workflow list in the document details: http://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/HEAD/root/projects/web-client/source/java/org/alfresco/web/ui/repo/component/UINodeWorkflowInfo.java

To get to the users who have tasks assigned you would then need to use getWorkflowPaths and getTasksForWorkflowPath methods of the WorkflowService.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top