cancel
Showing results for 
Search instead for 
Did you mean: 

How to createNode in java backed?

dark_rider
Champ on-the-rise
Champ on-the-rise
I am trying to create a new node but not success. How could I perform it? Basicly I want to copy a node and change its content.

final String NAMESPACE = "http://www.alfresco.org/model/demoscripts/1.0";
final QName PROP_QNAME_MY_PROPERTY = QName.createQName("custom.model", "myProperty");


NodeRef newNodeRef = getNodeService().createNode(parentRef, ContentModel.ASSOC_CONTAINS, QName.createQName(NAMESPACE, newNodeName), PROP_QNAME_MY_PROPERTY).getChildRef();

I get this exception
java.lang.IllegalArgumentException: Class {custom.model}myProperty has not been defined in the data dictionary

How can I create node simply? Could you please help me?
2 REPLIES 2

mrogers
Star Contributor
Star Contributor
Here's one I prepared earlier ….

          ChildAssociationRef child = nodeService.createNode(A4NodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName("A7"), ContentModel.TYPE_CONTENT);

I think your problem is with the last argument.    Have you really defined a type with the name myProperty?  :?

The error message is saying that alfresco does not know what type a  {custom.model}myProperty is.

dark_rider
Champ on-the-rise
Champ on-the-rise
Exactly you are right, the last argument was wrong, I have changed it with ContentModel.TYPE_CONTENT and it works.
There is no example about that so I could not know how it works.
Thanks you so much…