'Alfresco Add Category based on Tag
I would like to create a script to use as a folder rule to add a category based on the tag.
This script successfully adds the category to the file.
var catNodeRef = search.findNode("workspace://SpacesStore/XXXXXXXXXXXXXXXXXXXX");
var categories= document.properties["cm:categories"];
if (categories == null ) {
categories = new Array (); }
categories.push(catNodeRef);
document.properties["cm:categories"] = categories;
document.save();
};
However, when I add the findTaggedNodes, the script fails.
var taggedNodes = findTaggedNodes("workspace://SpacesStore/XXXXXXXXXtagnumber");
var taggable= document.properties["cm:taggable"];
if (taggedNodes == "workspace://SpacesStore/XXXXXXXXXtagnumber" )
{
var catNodeRef = search.findNode("workspace://SpacesStore/88b392ce-a50c-4079-a8cb-8a18faafc154");
var categories= document.properties["cm:categories"];
if (categories == null ) {
categories = new Array (); }
categories.push(catNodeRef);
document.properties["cm:categories"] = categories;
document.save();
};
I have also tried
var taggable= document.properties.hastag = "aaf observatory";
if(var taggable)
{
var catNodeRef = search.findNode("workspace://SpacesStore/88b392ce-a50c-4079-a8cb-8a18faafc154");
var categories= document.properties["cm:categories"];
if (categories == null ) {
categories = new Array (); }
categories.push(catNodeRef);
document.properties["cm:categories"] = categories;
document.save();
};
Any help would be appreciated. (NOTE: I am not a developer)
Solution 1:[1]
findTaggedNodes don't work in javascript, you can use it in Java with TaggingService , in JavaScript you need to use search.findNode(TAG_NODE_REF) to get the node of the tag with the nodeRef.
var taggable = document.properties["cm:taggable"]; return a collection of tags, you cannot compare it with string value. you need a loop to compare if the collection contain same node et use node1.equals(node2)
You find script here :
var nodeTag = search.findNode('workspace://SpacesStore/XXXXXXXXXtagnumber');
//Get Tags of document
var documentTags = document.properties["cm:taggable"];
for each(var tag in documentTags) {
if(tag.equals(nodeTag)) {
//Tag is found in document, add the category with function
addCAtegory(document, "workspace://SpacesStore/REF_ID_CATEGORY");
}
}
function addCAtegory(node, categoryNodeRef) {
var catNodeRef = search.findNode(categoryNodeRef);
var categories= node.properties["cm:categories"];
if (categories == null ) {
categories = new Array ();
}
categories.push(catNodeRef);
node.properties["cm:categories"] = categories;
node.save();
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
