Can I get a list of workflows to which a document is attached in Alfresco

I am trying to get a list of workflows that the document is attached to on the Alfresco webpage, but I'm kind of stuck.

My initial problem is that I have a list of files, and the current user can be assigned data streams with these documents. So, now I want to create a website that will look in a folder, take all the documents there and collect a list of documents along with links to tasks, if there are any for the current user.

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

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

+5
source share
3 answers

Well, for future reference, I found a way to get all active workflows in a document from javascript:

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

Unfortunately, the javascript API does not provide all the functions of a workflow. It looks like the list of workflow instances attached to the document only works in Java (or supported Java scripts).

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

The use of this can be found in the list of workflows 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

, , getWorkflowPaths getTasksForWorkflowPath WorkflowService.

+4

I used the packageContains association to find workflows for a document. Below I published the code in Alfresco JavaScript for active workflows (as zladuric answered), as well as 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();
+4
source

All Articles