10-03-2012 02:02 AM
10-04-2012 07:29 AM
10-05-2012 02:53 AM
Hello Irene,
this appears to be the same question as in https://forums.alfresco.com/en/viewtopic.php?f=5&t=46501. I provided an example there that - although not directly applicable - can be easily adapted to your use case. Your code does not seem to have evolved much from the first post. Did you have trouble with the example? Your last response in that thread did not indicate any problems.
Regards
Axel
10-05-2012 04:03 AM
var categoryToAdd = null;
var categories = classification.getRootCategories("cm:generalclassifiable");
var remainingNames = ["Document Review Status", "Approval"];
while(categoryToAdd == null && categories && remainingNames.length > 0){
var idx = 0, max = categories.length, innerCategories = categories;
// reset categories to prevent further iterations if we don't find a match
categories = null;
for(;idx < max; idx++){
var category = categories[idx];
if(category.name.equals(remainingNames[0])){
if(remainingNames.length == 1){
categoryToAdd = category;
}else{
categories = category.getSubCategories();
remainingNames.shift();
break;
}
}
}
}
if(categoryToAdd != null){
var oldCategories = document.properties["cm:categories"];
var newCategories = oldCategories != null ? oldCategories : [];
newCategories.push(categoryToAdd);
document.properties["cm:categories"] = newCategories;
document.save();
}
10-05-2012 04:43 AM
10-08-2012 12:00 AM
Hello Irene,_______________________________________________________________________________________________________________________
my example is a JavaScript. You can just incorporate it into your existing script in the appropriate places.
The following fragment from my example already provides the code necessary to get a specific category from a specific branch in the category tree (the remainingNames variable can be thought of as a path to your category):
var categoryToAdd = null;
var categories = classification.getRootCategories("cm:generalclassifiable");
var remainingNames = ["Document Review Status", "Approval"];
while(categoryToAdd == null && categories && remainingNames.length > 0){
var idx = 0, max = categories.length, innerCategories = categories;
// reset categories to prevent further iterations if we don't find a match
categories = null;
for(;idx < max; idx++){
var category = categories[idx];
if(category.name.equals(remainingNames[0])){
if(remainingNames.length == 1){
categoryToAdd = category;
}else{
categories = category.getSubCategories();
remainingNames.shift();
break;
}
}
}
}
Then you only need to use the category reference (a ScriptNode, since the category is a full content object) to modify the cm:categories property (the collection of applied categories) of any document you wish to update. This is what this fragment is for:
if(categoryToAdd != null){
var oldCategories = document.properties["cm:categories"];
var newCategories = oldCategories != null ? oldCategories : [];
newCategories.push(categoryToAdd);
document.properties["cm:categories"] = newCategories;
document.save();
}
It takes the category that we want to add and inserts it into the collection of applied categories. In your case, you may need to remove the previous state category, i.e. the category you want to replace due to the approval state change.
Regards
Axel
10-08-2012 03:45 AM
10-08-2012 05:33 AM
10-08-2012 05:59 AM
Hello Irene,_________________________________________________________________________________________________________________________
as I wrote, I did not run / test the script, simply wrote it based on the API and previous, similar scripts.
For "getSubCategories()" you may try the alternative "category.subCategories" method of access.
Do you have a line number for the "0.0 from null" error? There is only one access in the code where "0" is used as an index and I don't see that as a possible candidate.
Regards
Axel
10-08-2012 06:18 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.