cancel
Showing results for 
Search instead for 
Did you mean: 

API differences Javascript vs JAVA

darkredd
Star Contributor
Star Contributor
Hello everyone,

A silly question perhaps, however here goes: I am trying to leverage an already existing custom action which creates document links.
I have a slight lack of understanding of API differences.

In Javascript I am able to use the custom action's logic to create link with a script (Action Rule). But using Java with the same logic I do not get the same output.

Javascript
fNode.createNode(sNode.name + " Link", "{custom.uri}filelink", pr)

Where <strong>pr</strong> is a list of properties to be attached to the newly created link.

Java
nodeService.createNode(parentDest, ContentModel.ASSOC_CONTAINS, QName.createQName(LINK_URI), ContentModel.TYPE_CONTENT, linkParams)

Where <strong>linkParams</strong> is a list of properties to be attached to the newly created link.
I did not use the <strong>FileFolderService</strong> because it does not offer me a way to attach properties to the node.

With javascript I am able to create a link as if I had clicked on a document Library action itself, but with JAVA it just creates a new node altogether without any reference to the source node.

Am I misusing the JAVA API or is there just a difference entirely?
3 REPLIES 3

mrogers
Star Contributor
Star Contributor
IIRC I don't think you can have properties on an association.    Well except the name and type which are special cases.   linkParams are actually properties for the new node.

I suspect your LINK_URI is not correct.   There is a convention to follow that is enforced by the file folder service.

darkredd
Star Contributor
Star Contributor
Hi mrogers,

Thanks for your response. However my "LINK_URI" is correct because it's a copy and paste of the uri which I use in javascript. On the original post <strong>{custom.uri}</strong> is a replacement of the actual uri which in fact is assigned to LINK_URI. Based on your response I would think I am then uri the NodeService.create() method in a wrong, specifically when it come the association part.
What would you suggest I look at to achieve this?

darkredd
Star Contributor
Star Contributor
Hi,

I managed to find a solution to my problem. As suspected it was lack of understanding of the API. I had placed my arguments in the wrong order as expected by the method, and one QName ("ContentModel.TYPE_CONTENT") was wrong. In the end I had to change the method to look like this:
<strong>This is the new order:</strong>
nodeService.createNode(parentDest, ContentModel.ASSOC_CONTAINS, ContentModel.TYPE_LINK, QName.createQName(LINK_URI), linkParams)


<strong>The one with an error was:</strong>
nodeService.createNode(parentDest, ContentModel.ASSOC_CONTAINS, QName.createQName(LINK_URI), ContentModel.TYPE_CONTENT, linkParams)


Now I am able to achieve what I had set out to do.
Thank you.