cancel
Showing results for 
Search instead for 
Did you mean: 

Where to look for categories?

alina
Champ in-the-making
Champ in-the-making
Hello everybody,
I'm a total newbie to Alfresco scripting, but I have an urgent task, that has to be completed 'yesterday'. I'm a PHP& JavaScript programmer, but I do not yet understand the object model and the framework in Alfresco.

My task is to create category tree according to a structure stored elsewhere (XML, plain text or database).
I've found LOTS of info, but I can't put it all together.
The question is - where in the object model I can find categories? (those I can manage through Administration Console - Category Management) What is their root object?
14 REPLIES 14

afaust
Legendary Innovator
Legendary Innovator
Yes - category search / navigation in admin view uses index and if there is some corruption, this may explain your issues.

alina
Champ in-the-making
Champ in-the-making
ОК, Аxel, thanks A LOT for your help. Your advice was very useful.

alina
Champ in-the-making
Champ in-the-making
I'm stuck again.

This weekend the indexes were rebuilt, so the code
var size = classification.getAllCategoryNodes("cm:generalClassifiable").length;
works ok.

Now I can get the full list of the categories, but I cannot find categories by name.

var nodes = classification.childByNamePath("Test");
gives me

Message:   07200006 Wrapped Exception (with status template): 07200446 Failed to execute script '/test/folder1.get.js (in repository store workspace://SpacesStore/Company Home/Data Dictionary/Web Scripts Extensions)': 07200445 TypeError: Cannot find function childByNamePath. (workspace://SpacesStore/Company Home/Data Dictionary/Web Scripts Extensions/test/folder1.get.js#1)
   
Exception:   org.mozilla.javascript.EcmaError - TypeError: Cannot find function childByNamePath. (workspace://SpacesStore/Company Home/Data Dictionary/Web Scripts Extensions/test/folder1.get.js#1)

What's wrong? How can I find a category by its name?

afaust
Legendary Innovator
Legendary Innovator
Hello,

you can't use childByNamePath on classification as this is not a propert ScriptNode. You need to obtain the root node to search from first. Unfortunately, you can only obtain root categories via classification, not the absolute root node for the entire category tree. This means you have to look up a root category via JavaScript loop and name checks, while any category below a root category may be found via childByNamePath relative to that root category node.

Please be aware that if you use childByNamePath you will NOT end up with a CategoryNode - all elements returned are simple ScriptNode, which lack some category related functionality. The only alternative to this is implementing your own JavaScript based lookup which uses the getRootCategories (classification) and getSubCategories (CategoryNode) functions and finds your target category via loop and compare operations.

Regards
Axel

alina
Champ in-the-making
Champ in-the-making
It's sad. Smiley Happy Thanks, Axel.
Unfortunately, in Alfresco 3.4. there is even no method called getSubCategories. So my task is simple - to loop through all the categories.


Alina
Getting started

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.