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.
JavaScript
x
11
11
1
var catNodeRef = search.findNode("workspace://SpacesStore/XXXXXXXXXXXXXXXXXXXX");
2
var categories= document.properties["cm:categories"];
3
4
if (categories == null ) {
5
categories = new Array (); }
6
7
categories.push(catNodeRef);
8
document.properties["cm:categories"] = categories;
9
document.save();
10
};
11
However, when I add the findTaggedNodes, the script fails.
JavaScript
1
16
16
1
var taggedNodes = findTaggedNodes("workspace://SpacesStore/XXXXXXXXXtagnumber");
2
var taggable= document.properties["cm:taggable"];
3
if (taggedNodes == "workspace://SpacesStore/XXXXXXXXXtagnumber" )
4
5
{
6
var catNodeRef = search.findNode("workspace://SpacesStore/88b392ce-a50c-4079-a8cb-8a18faafc154");
7
var categories= document.properties["cm:categories"];
8
9
if (categories == null ) {
10
categories = new Array (); }
11
12
categories.push(catNodeRef);
13
document.properties["cm:categories"] = categories;
14
document.save();
15
};
16
I have also tried
JavaScript
1
15
15
1
var taggable= document.properties.hastag = "aaf observatory";
2
3
if(var taggable)
4
{
5
var catNodeRef = search.findNode("workspace://SpacesStore/88b392ce-a50c-4079-a8cb-8a18faafc154");
6
var categories= document.properties["cm:categories"];
7
8
if (categories == null ) {
9
categories = new Array (); }
10
11
categories.push(catNodeRef);
12
document.properties["cm:categories"] = categories;
13
document.save();
14
};
15
Any help would be appreciated. (NOTE: I am not a developer)
Advertisement
Answer
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 :
JavaScript
1
28
28
1
var nodeTag = search.findNode('workspace://SpacesStore/XXXXXXXXXtagnumber');
2
//Get Tags of document
3
var documentTags = document.properties["cm:taggable"];
4
5
for each(var tag in documentTags) {
6
7
if(tag.equals(nodeTag)) {
8
9
//Tag is found in document, add the category with function
10
addCAtegory(document, "workspace://SpacesStore/REF_ID_CATEGORY");
11
}
12
}
13
14
function addCAtegory(node, categoryNodeRef) {
15
16
var catNodeRef = search.findNode(categoryNodeRef);
17
var categories= node.properties["cm:categories"];
18
19
if (categories == null ) {
20
categories = new Array ();
21
}
22
23
categories.push(catNodeRef);
24
node.properties["cm:categories"] = categories;
25
node.save();
26
}
27
28