cancel
Showing results for 
Search instead for 
Did you mean: 

Create a discussion topic through Javascript API

kkaragitz
Champ in-the-making
Champ in-the-making
Is this possible?  with 1.3?  if so a snipit of code would be great.
8 REPLIES 8

kevinr
Star Contributor
Star Contributor
A discussion, like most other objects in Alfresco is just a node of a certain type, and you can use the JavaScript API to create nodes of any type. If you want to do this kind of thing, i suggest you download the SDK and then take a look at the data model XML files, in this case "forumModel.xml" - it contains the definitions of the various objects created by the forums module. You can then use the JavaScript API method:
Node createNode(string name, string type)
where the 'type' is the type from the data model, in your example it would be the 'fm:topic' type. Of course you would need to create it inside a parent forum node for it to be useful.

Thanks,

Kevin

kkaragitz
Champ in-the-making
Champ in-the-making
Kevin,

Thanks for the response.  I've downloaded the sdk.

ajshaw
Champ in-the-making
Champ in-the-making
Is it possible to manipulate the content on nodes created using createNode("MyNode", "My:NodeType"); ?

The following doesnt work:

theNode = createNode("MyNode", "My:NodeType");
theNode.content = "Lalalalal";


This doesn't work for types extending cm:content, and also for the following:

createNode("MyNode", "cm:content");


Thanks.

kevinr
Star Contributor
Star Contributor
That should all work fine, as long as the My:NodeType extends cm:content.

Thanks,

Kevin

ajshaw
Champ in-the-making
Champ in-the-making
That's the problem. It does extend cm:content, and and it doesn't work. I tried it after some guys from Holland couldn't get it to work either.

If anyone can make it work, let me know!

(Alfresco comunity 1.4 btw.)


Also, i didn't highight very well:

createNode("MyNode","cm:content");   <——CM:CONTENT!!!!

which implies that the nodetype isn't nessecarily the issue, but that the content cannot be altered on nodes using createNode, rather than createFile. If that makes sense. Please let me know if i'm just missing something Smiley Happy

kevinr
Star Contributor
Star Contributor
I have investigated the problem, you are correct there is a subtle bug that the content property cannot be set if the node is created using the createNode() method. The createFile() method calls the FileFolderService which internally has an extra step to create an empty content property.

I have raised a JIRA issue for it:
http://issues.alfresco.com/browse/AR-1066

Thanks for reporting this,

Kevin

ajshaw
Champ in-the-making
Champ in-the-making
Thanks Kevin.

kevinr
Star Contributor
Star Contributor