How to get tags of my document

cancel
Showing results for 
Search instead for 
Did you mean: 
imanez1
Active Member II

How to get tags of my document

Jump to solution

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 Solution

Accepted Solutions
francesco_forna
Partner

Re: How to get tags of my document

Jump to solution

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 solution in original post

3 Replies
francesco_forna
Partner

Re: How to get tags of my document

Jump to solution

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.

imanez1
Active Member II

Re: How to get tags of my document

Jump to solution

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

francesco_forna
Partner

Re: How to get tags of my document

Jump to solution

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"]);
}