cancel
Showing results for 
Search instead for 
Did you mean: 

Persisting Aspect Properties

slothrop
Champ in-the-making
Champ in-the-making
In Alfresco 2.1 I am writing JavaScript that moves the contents of a space into another space.  I have an aspect defined that includes the boolean property, customSmiley TonguerimaryDocument.  I would like the user to designate one of the documents in the space as the primary document before submitting the contents of the space.  However, if there is only one document I thought I could assign it to be true in my JavaScript and proceed with processing the submission even if the user has not designated the document as the primary one.

So in my code, if there is only one document in the folder I have the following (I have discovered that when there is only one document in the space, there is also another noncontent node and space.children.length = 2 and the noncontent node is space.children[0]):

children[1].properties["custom:PrimaryDocument"] = true;
children[1].save;

Later in the code I test this:

child = children[1];
if(child.properties["custom:PrimaryDocument"]) "do something"
child.save;
child.move(newFolder);

The test evaluates to true and the code executes but when I move the document to the new space, the property is still false.  How can I make this assignment persist?

Thanks.
3 REPLIES 3

kevinr
Star Contributor
Star Contributor
There is nothing wrong with the code that i can see (you don't need to call save() in the second section though if you haven't made any changes - but it won't hurt).

What happens in the destination folder? Are there any rules or further scripts executing that could change the value back?

Thanks,

Kevin

slothrop
Champ in-the-making
Champ in-the-making
No, this happens even when the destination folder has no rules or scripts applied.  There is a workaround which involves removing the aspect and readding it so I can set children[1].properties["customSmiley TonguerimaryDocument"] to be true.  It persists when I do the following:

   var notes = children[1].properties["custom:Notes"];
      var containsOnlineMaterial = children[1].properties["custom:ContainsOnlineMaterial"];
      children[1].removeAspect("custom:OtherProperties");
      var otherProps = new Array(3);
      otherProps["custom:Notes"] = notes;
      otherProps["custom:ContainsOnlineMaterial"] = containsOnlineMaterial;
      otherProps["custom:PrimaryDocument"] = true;
      children[1].addAspect("custom:OtherProperties", otherProps);

However, this resembles a problem I posted earlier with the Alfresco-defined property, cm:author, when it is copied, but not when it is moved.  The workaround,


var author = child.properties["cm:author"];
   child.removeAspect("cm:author");
   var props = new Array(1);
   props["cm:author"] = author;
   child.addAspect("cm:author", props);
   child.save;
   child.copy(newFolder);

doesn't work here.

http://forums.alfresco.com/viewtopic.php?t=8532&highlight=

kevinr
Star Contributor
Star Contributor
I haven't tried your use case myself, but if what you say is happening then it sounds like a bug. I have raised a JIRA item so we can take a look:
http://issues.alfresco.com/browse/AR-1772

Thanks,

Kevin