Question

In the course of my workflow, I want to be able to set a variable using a document aspect. Now I know to set a variable using the property of a document I would do something like...

task.setVariable('wf_caseType', bpm_package.children[0].properties["hearing:caseType"]);

And that's just based on looking at the Alfresco Javascript API. However, I have not seen anything on retrieving the aspect of a document.

What I've done so far is in some javascript that gets executed when a file is brought over to a certain space, we create this aspect called caseID similar to below..

var caseID=0

var props=new Array(1);
props["wf:caseIDNum"]=caseID;
var newAspect=newNewSpaceName.addAspect("wf:caseID",props);

And what that does is basically add the caseID aspect to the folder that gets created in the script, and subsequently the documents within that folder also inherit this aspect.

So I was thinking adding that to a variable might work the same way, i.e:

task.setVariable('wf_caseId', bpm_package.children[0].aspect["hearing:caseId"]);

However, that has proved to not be the case. Does anyone have any experience doing this or perhaps could offer some advice here?

Was it helpful?

Solution

When an aspect has been added to a node, you can get/set any of its properties like you would any of the properties defined by the node's content type. There is no difference. So your first setVariable call would work whether hearing:caseType is defined in a type or an aspect.

OTHER TIPS

The JavaScript API page describes the aspects attribute for the ScriptNode object:

aspects A readonly array of the aspects (as fully qualified QName strings) applied to the node. (This is returned as a Java HashSet)

Your question refers to "aspect" (singular) - but nodes will often (usually?) have multiple aspects

The JavaScript API Cookbook page that you linked to also has examples of adding asects to a node.

Updated: Now that you've updated the question, I see that you want to access properties defined in an aspect - see Jeff's answer that addresses this!

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