I wanted to have a default topic to the document, like feed back I wanted to allow all of the viewers of the document to give their feed back in this topic discussion.
When we create content it should be created by default to that content.
You could do this using rules and the JavaScript API. You would create a rule on the root space (make it inherited so that child spaces use it also) and execute a script that adds the appropriate objects to the new document node to build the first forum post. The tricky bit is knowing which objects to build like most concepts in Alfresco, forums/posts/topics are just nodes and aspects of a specific type. It will require some investigation to work out which aspects and types to apply/build. The best place to start is to download the SDK and examine the forumModel.xml to see how the forums are constructed.
I have been working on the following script under Alfresco 2.0.0
// script to start discussion on a document if (document.isDocument && !document.hasAspect("fm:discussable")) { var nForum = space.createNode(document.properties["cm:name"] + " discussion","fm:forum"); nForum.properties["cm:title"]= document.properties["cm:name"] + " discussion"; nForum.save(); var nTopic = nForum.createNode("General discussion","fm:topic"); nTopic.save(); //document.addAspect("fm:discussable"); }
When the last line is uncommented, an integrity error is thrown: 17:05:41,124 ERROR [node.integrity.IntegrityChecker] Found 1 integrity violations: The association child multiplicity has been violated: Association: Association[ class=ClassDef[name={http://www.alfresco.org/model/forum/1.0}discussable], name={http://www.alfresco.org/model/forum/1.0}discussion, target clas s={http://www.alfresco.org/model/forum/1.0}forum, source role=null, target role=null] Required child Multiplicity: 1..1 Actual child Multiplicity: 0 17:05:41,130 ERROR [util.transaction.SpringAwareUserTransaction] Transaction didn't commit org.alfresco.repo.node.integrity.IntegrityException: Integrity failure
The model structure is defined in the usual place (alfresco/WEB-INF/classes/alfresco/model/forumModel.xml).
I have used the UI to create a forum on a content node and used the node browser to investigate the resulting structure. It appears the forum folder is created in the space containing the document and an association is created defining that folder as the content's discussion.
You are correct in your assumptions on what types etc. to create. Unfortunately I was mistaken in that you can current use the JavaScript API to create the forum structure the method that you require I have only recently added:
you need this as the 'fm:forum' node you create must be associated as a child association to the content node. The child node you have created will have the default association name which is not what you want, you need the child association name to be "fm:discussion" as per the model. This is why your script goes bang when you add the aspect - it is expecting that association to be created. You can do this if you checkout the latest code from our public SVN or take a nightly build. Sorry if this causes you problems.
The good news is that in the latest code (2.1) the JavaScript API has been expanded to allow more low-level operations such as the createNode with association name (as I mentioned above), createNode for non content/folder types, create/delete/modify of target/child associations. And createNode also supports creating types that require mandatory properties at creation time.