cancel
Showing results for 
Search instead for 
Did you mean: 

how to retrieve the document's category list?

rluberti
Champ in-the-making
Champ in-the-making
hi,

I'm trying to retrieve and eventually  add/delete categories in a document…
reading the JavaScript API it is not clear how to do it…
where can I get an example of it?

thanks
2 REPLIES 2

rluberti
Champ in-the-making
Champ in-the-making
thanks for your help and sorry for my late reply….I'm posting the solution below:


var cats = document.properties["cm:categories"];

//list categories
for (var i = 0; i < cats.length ; i++)
{
   var catName = cats[i].name;
   document.content += "—————>"+catName+"\n";
   
}

//add one category
var root_cats =  classification.getRootCategories("cm:generalclassifiable");
var cat = root_cats[1];

cats.push(cat);

document.properties["cm:categories"] = cats;
document.save();

mphasis
Champ in-the-making
Champ in-the-making
well just an addition to the above quote.

incase you are uploading content from scratch

you will need to add following line at the start

upload.addAspect("cm:generalclassifiable");

and maybe current categories you will get null.

Please check that.