cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing package attributes in workflow

srobinson
Champ in-the-making
Champ in-the-making
I am using Alfresco Community 4.2.d and I have a workflow where I use a service task to initially setup users and process variables. I have a need to get property information from the document that is stored in the workflow package. My question is how do I do this through my service task class? I see how I can use the WorkflowService to get the workflow package contents, but that method requires a taskId and I am having difficulty getting access to the current service task id through the DelegateExecution object that my service task has access to.

Any help on this is greatly appreciated.

Thanks,

- Shannon
1 REPLY 1

frederikherema1
Star Contributor
Star Contributor
The delegateExecution contains a property "package" (or something similar, there is a constant on WorkflowModel or BpmModel for this). This is just a plain node-ref and contains references to all the documents that are attached. If you look at the source of the WorklfowServiceImpl you see this clearly, you can just use the node service to fetch child-assocs and fetch properties of the document afterwards (I presume you're not using AVM, this has a different lookup-method):


private List<NodeRef> getRepositoryPackageContents(NodeRef workflowPackage)
    {
        List<NodeRef> contents = new ArrayList<NodeRef>();
        // get existing workflow package items
        List<ChildAssociationRef> packageAssocs = protectedNodeService.getChildAssocs(workflowPackage);
        for (ChildAssociationRef assoc : packageAssocs)
        {
            // create our Node representation from the NodeRef
            NodeRef nodeRef = assoc.getChildRef();
            QName assocType = assoc.getTypeQName();
            if (!protectedNodeService.exists(nodeRef))
            {
                if (logger.isDebugEnabled())
                    logger.debug("Ignoring " + nodeRef + " as it has been removed from the repository");
            }
            else if (!ContentModel.ASSOC_CONTAINS.equals(assocType) && !WorkflowModel.ASSOC_PACKAGE_CONTAINS.equals(assocType))
            {
                if (logger.isDebugEnabled())
                    logger.debug("Ignoring " + nodeRef + " as it has an invalid association type: "+assocType);
            }
            else
            {
                if (checkTypeIsInDataDictionary(nodeRef))
                {
                    contents.add(nodeRef);
                }
            }
        }
        return contents;
    }

Another alternative is to use a script-task, this has single-lmine access to document-properties in the packages, using an expression…