cancel
Showing results for 
Search instead for 
Did you mean: 

document.properties = null

pigtaro
Champ in-the-making
Champ in-the-making
Hi All,

This is my first post. I am trying to add category to a new document. From the web, i got the following code:


var catNodeRef = search.luceneSearch("…");
var cats = document.properties["cm:classifiable"];
cats.push(catNodeRef);

I keep getting null error. After turning on the Alfresco Javascript debugger, i discovered that document.properties is null. Been searching for the web ever since, but unable to get answer. How do i instantiate the properties attributes in the document?

regards,
Steven
5 REPLIES 5

damiar
Champ in-the-making
Champ in-the-making
I think you have to post the code that creates 'document', because with the code you've posted there's no way to know the type of that variable.

pigtaro
Champ in-the-making
Champ in-the-making
Apologise… still newbie is alfresco…

I want to execute my script in the rule, so that i can tag any incoming documents with a category.

My script is actually this: 


document.addAspect("cm:versionable");
document.addAspect("cm:generalclassifiable");

for each (cl in classification.getAllCategoryNodes("cm:generalclassifiable")){
  if(cl.name == "Test Plan"){
     document.properties["cm:categories"].push(cl);
  }
}

document should point to the incoming file because the addAspect works. However, the document.properties is null, so the following line give a null error.

document.properties["cm:categories"].push(cl);

Hope my explanation of my problem is clear.

pigtaro
Champ in-the-making
Champ in-the-making
After experimenting, i found that it is not document.properties = null.

This is what i derive, so please correct me if i am wrong. When i add aspects to a document, document.properties has added properties based on the contentModel.xml. So when i add versionable, cm:versionLabel, cm:initialVersion, cm:autoVersion is added into the docment.properties.

However, when i addAspects("cm:generalclassifiable"), no new properties are added into the document.properties. The contentModel for the generalclassifiable is as follows, i did not make any changes to it, so it is what was downloaded in the alfresco package.


      <aspect name="cm:generalclassifiable">
         <title>General Classifiable</title>
         <parent>cm:classifiable</parent>
         <properties>
            <property name="cm:categories">
               <title>Categories</title>
               <type>d:category</type>
               <mandatory>false</mandatory>
               <multiple>true</multiple>
               <index enabled="true">
                  <atomic>true</atomic>
                  <stored>true</stored>
                  <tokenised>true</tokenised>
               </index>
            </property>        
         </properties>
      </aspect>

rogier_oudshoor
Champ in-the-making
Champ in-the-making
So the solution would be to, if your attribute cm:categories doesn't yet exist, to create an array and initialize your attribute with it.

pigtaro
Champ in-the-making
Champ in-the-making
Ha… got it working after creating an empty array and initialize the "cm:categories" to the document.properties. Thanks rogier.oudshoorn.