cancel
Showing results for 
Search instead for 
Did you mean: 

How to get tags of my document

imanez1
Confirmed Champ
Confirmed Champ

I want to get the Tags of my document (in javascript) so that i can execute a script:

example: If my document is tagged "test" execute the rest of my script .

I know it is possible via the rules of the folder, but i want it via javascript like the case with categories:

 

var cats = document.properties["cm:categories"];
for (var i = 0; i < cats.length ; i++){
   var catName = cats[i].name;
}

I tried with this but it's not working:

List<String> tags = taggingService.getTags(document);
logger.log(tags);

1 ACCEPTED ANSWER

Hi,

var tags = document.properties["cm:taggable"];
for (var i = 0; i < tags.length ; i++){
   var tagNodeRef = tags[i];
   logger.info('------------------------------------------- ' + tagNodeRef.properties["cm:name"]);
}

View answer in original post

3 REPLIES 3

francesco_forna
Confirmed Champ
Confirmed Champ

Hi,

you have to inspect the cm:taggable aspect. This aspect is bound to tag noderefs.

So document.properties["cm:taggable"] returns tag noderefs bound to the document node, such as the cm:categories aspect.

I don't know how to use that, can you give me an example?

Hi,

var tags = document.properties["cm:taggable"];
for (var i = 0; i < tags.length ; i++){
   var tagNodeRef = tags[i];
   logger.info('------------------------------------------- ' + tagNodeRef.properties["cm:name"]);
}