cancel
Showing results for 
Search instead for 
Did you mean: 

Automatic tagging of category

irene08
Champ in-the-making
Champ in-the-making
Hi! Good Day!

Can someone help me with this? I need to set an automatic tagging of file. For example, if all approvers/reviewers approved the file, it will automatically have the "APPROVAL" category/tag.

I set a category in category root. Category Name is 'Document Review Status' and the subcategories are 'Draft', 'Reviewed', 'Approval', 'Published', 'Abandoned'.

I did this code in parallel-review-group-bpmn20.xml. And it has no effect. I'm not sure if my code is right. I don't know how to set an if statement in xml.
—————————————————————————————————————————————————
<!– ADDED CODE –>
   <activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
                  <activiti:field name="script">
                     <activiti:string>
                  if (wf_requiredApprovePercent = wf_actualPercent)
                  {cm:name="Approval";}
                </activiti:string>
                  </activiti:field>
    </activiti:taskListener>
<!– ADDED CODE –>
—————————————————————————————————————————————————-

Thank you for your help. It will be much appreciated.

Irene
1 REPLY 1

jpotts
World-Class Innovator
World-Class Innovator
First, realize that you are writing JavaScript that will be run by Alfresco. That means pretty much anything you can do with the Alfresco JavaScript API you can do here.

If you don't already have it installed, I highly recommend you download and install Florian Maul's JavaScript Console. You can use that to test your JavaScript and practice other cool JavaScript tips/tricks. Plus it has links to all of the documentation.

For example, here is one way to add a category to a document using JavaScript:
var cats = search.luceneSearch("PATH:\"/cm:generalclassifiable/cm:Languages/cm:French\"");
englishCatNode = cats[0];

var docs = search.luceneSearch("@cm\\:name:\"sample-a.pdf\"");
var doc = docs[0];
print(doc.name);
if (!doc.hasAspect("cm:generalclassifiable")) {
  doc.addAspect("cm:generalclassifiable");
}

var currentCats = doc.properties['cm:categories'];
if (currentCats == null) {
  currentCats = new Array();
}
currentCats.push(englishCatNode);
doc.properties['cm:categories'] = currentCats;
doc.save();

In your case, you don't need to search for the document–you can get it from the workflow package. Assuming you only want to set the category on the first document in the package, your code would look something like:
<activiti:taskListener event="complete" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
<activiti:field name="script">
<activiti:string>
if (wf_requiredApprovePercent == wf_actualPercent)
{
var cats = search.luceneSearch("PATH:\"/cm:generalclassifiable/cm:Document_x0020_Review_x0020_Status/cm:Approved\"");
approvedCatNode = cats[0];

var doc = bpm_package.children[0];
if (!doc.hasAspect("cm:generalclassifiable")) {
  doc.addAspect("cm:generalclassifiable");
}

var currentCats = doc.properties['cm:categories'];
if (currentCats == null) {
  currentCats = new Array();
}
currentCats.push(approvedCatNode);
doc.properties['cm:categories'] = currentCats;
doc.save();
}
</activiti:string>
</activiti:field>
</activiti:taskListener>

Hope that helps you get pointed in the right direction. If you get stuck, please check http://docs.alfresco.com for JavaScript syntax.

Jeff