Search code examples
javascriptalfresco

Alfresco apply category with js to doc


How to apply category to document in Alfresco with javascript?

tried like this:

document.properties["cm:categories"] = "testCat";

UPDATE:

like this I am able to get "root categories" but not "sub categories":

var rootCats =  classification.getRootCategories("cm:generalclassifiable");
document. properties["cm:categories"] = rootCats[3];

this doesnt work:

document. properties["cm:categories"] = rootCats[3][1];

Solution

  • I found it out, if someone need it this is the way how it cana be done

    get all root categories [audio, video, image, ...]

    var rootCats =  classification.getRootCategories("cm:generalclassifiable");
    

    get subcategories from desired root category -> sub category from "video" [horror, comedy, ...]

    var singleCat = rootCats[1].subCategories; 
    

    apply category to document -> apply "horror" to document

    doc. properties["cm:categories"] = singleCat[0]; //app
    

    save it

    doc.save();