cancel
Showing results for 
Search instead for 
Did you mean: 

Add a category with a JavaScript rule

simon
Champ in-the-making
Champ in-the-making
I would like to add a new category to a document using the JavaScript API: add a category "archived" for some documents and move them to an Archive folder (this folder may not exsist and has to be created at that point).

This isn't possible with the current JavaScript API or I can't find it in the documentation. Is there some other workaround to make this work?

These are some other ideas that didn't work out:
  • Add the category to the "Archived" space, when the document is moved to this space the category would be applied automatically. Didn't do the trick, the Archived space is created on the fly when needed and I can create a folder with JavaScript but I can't add a rule at that point.

  • Create a simple workflow rule that moves the document to some other folder where the category can be applied and move the document back to the Archive folder with a JavaScript rule that determs the right Archive folder. Didn't try this yet but it's not the best solution…

  • Don't create a simple new space but create a space with a template (like the advanced space wizard). This would allow me to add the category rule on the template folder but this isn't feasible at this point, the JavaScript API can't start from a template.
2 REPLIES 2

kevinr
Star Contributor
Star Contributor
I would like to add a new category to a document using the JavaScript API: add a category "archived" for some documents and move them to an Archive folder (this folder may not exsist and has to be created at that point).

This isn't possible with the current JavaScript API or I can't find it in the documentation. Is there some other workaround to make this work?

You are correct there is no direct support for categories in the 1.3 JavaScript API - but since categories are just an aspect and a property applied against a node then it is possible to do.

Categories on a node are stored in a property called "cm:categories" which is applied via the "cm:generalclassifiable" asect and multi-valued of type d:NodeRef. So you could in theory use the JavaScript API to select the category you want (using an XPath or Lucene search to get the category node) and then apply the "cm:generalclassifiable" aspect and set the "cm:categories" property to the selected category node against your destination node. So not simple, but it is possible to do Smiley Happy

Thanks,

Kevin

simon
Champ in-the-making
Champ in-the-making
This method could solve the problem, thanks Kevin!