cancel
Showing results for 
Search instead for 
Did you mean: 

javascript problem

thk
Champ on-the-rise
Champ on-the-rise
Hi,

I have many folders for meetings and in many of this meeting-folders are sub-folders with the name "English" which contains documents with presentations in English. I want to categorize all documents in all sub-folders with the Name "English". So for this first I have to search for all sub-folders with the name "English" and then categorize all docs in it (asigning an already existing category "English").
This seems not to be possible just with a simple rule. I seems the rule has to execute a script to do the task. I tried to write a Javascript-Script but I`m no Javascript programmer. I alos don`t know how to find the correct path name (in the DocumentLibrary of my site I have a folder Meetings, in it sub-folders for every meeting and in these meeting-folders sub-folders with the name "English")

Something like this doesn`t work:

var nodes = search.luceneSearch("<Sitename>/Meetings/", "English");
var categories = new Array(10);
categories.push("English");
for (var node in nodes){
   for each (doc in node.children)
      doc.properties["cm:categories"] = categories;
      doc.save();
   }
}


Thanks for any help
2 REPLIES 2

thk
Champ on-the-rise
Champ on-the-rise
Hi,

can anybody help me there?
I tried to make it simple to get closer to a solution of my problem. I just want to add a category "testcat" to the folder "test" by using a javascript. The folder is located in the documentLibrary of a site with the name "sitename".
I uploaded the script into Data Dictionary/Scripts and added a rule "execute script" (and choosing this javascript to execute) to the folder "test".
I added the aspect "classifiable" to the folder "test". Then I run the rule, but the folder "test" still has no category "testcat".

What`s wrong with my script? Below my script.

Thanks for any help.

var catnode = search.luceneSearch("testcat")[0];
var node = companyhome.childByNamePath("Sites").childByNamePath("sitename").childByNamePath("documentLibrary").childByNamePath("test");
var cats = node.properties["cm:categories"];
var newCats = new Array();
for (var i=0; i<cats.length; i++)
{
   newCats = cats;
}
newCats.push(catnode);
node.properties["cm:categories"] = newCats;
node.save();

thk
Champ on-the-rise
Champ on-the-rise
ok, now at least my script is working partly:
var catnode = search.luceneSearch("PATH:\"/cm:generalclassifiable//cm:Place\"")[0];
var nodes = search.luceneSearch("PATH:\"/app:company_home/st:sites/cm:myside/cm:documentLibrary/cm:test/*\" AND cm:name:\"English\"");
for (var node in nodes) {
   for each (n in node.children)
   {
   //   if (n.isDocument) {
         var cats = n.properties["cm:categories"];
         var newCats = new Array();
         if (cats != null) {
            for (var i=0; i<cats.length; i++)
            {
               newCats = cats;
            }
         }
         newCats.push(catnode);
         n.properties["cm:categories"] = newCats;
         n.save();
   //   }
   }
}


What is not working is this line:
var nodes = search.luceneSearch("PATH:\"/app:company_home/st:sites/cm:myside/cm:documentLibrary/cm:test/*\" AND cm:name:\"English\"");

I have in my documentlibrary for each meeting a folder and in each meeting folder there is a sub folder for the presentation in the respective language, for example a sub folder "English". The search should not search the complete repository but only what is under a specified directory "test" which contains all the meeting folders. The lucene search should return all folders with the name "English", but there seems to be a syntactical error since I get:
ERROR [org.alfresco.repo.action.AsynchronousActionExecutionQueueImpl] [defaultAsyncAction5] Failed to execute asynchronous action: Action[ id=8fdfc5e0-e3d8-4bbc-8d95-4359d3e59204, node=workspace://SpacesStore/8fdfc5e0-e3d8-4bbc-8d95-4359d3e59204 ]: 05250526 Request failed 400 /solr4/alfresco/alfresco?wt=json&fl=DBID%2Cscore&rows=1000&df=TEXT&start=0&locale=pt_BR&alternativeDic=DEFAULT_DICTIONARY&fq=%7B%21afts%7DAUTHORITY_FILTER_FROM_JSON&fq=%7B%21afts%7DTENANT_FILTER_FROM_JSON
org.alfresco.scripts.ScriptException: 05250532 Failed to execute script 'workspace://SpacesStore/b693c100-6dae-4716-80fa-d4415e8a0222': 05250528 Failed to execute search: PATH:"/app:company_home/st:sites/cm:myside/cm:documentLibrary/cm:test/*" AND cm:name:"English"

I also tried:
var nodes = search.luceneSearch("PATH:\"/app:company_home/st:sites/cm:myside/cm:documentLibrary/cm:test/*\" AND @cm\\:name:\"English\"");

Now I get no error message any more but still nothing happens (no category was added)



Since I`m really stuck here I appreciate any help.