cancel
Showing results for 
Search instead for 
Did you mean: 

Create link to a folder.

atkiba
Champ in-the-making
Champ in-the-making
Hi

I need to create a webscript to make links to folders from one site to another but I cannot find a function to do it, is there any function for this? I know there is a type link but I don't know how to create a node of that type.

Any help would be appreciated.
2 REPLIES 2

kaynezhang
World-Class Innovator
World-Class Innovator
There is no difference between creating a node of link type and creating a node of other types.
Just passing ApplicationModel.TYPE_FILELINK or ApplicationModel.TYPE_FOLDERLINK as nodeTypeQName to NodeService.createNode() method,and adding ContentModel.PROP_LINK_DESTINATION property to your properties map will be ok.

ApplicationModel.TYPE_FILELINK and ApplicationModel.TYPE_FOLDERLINK are subtypes of cm:link.

Here is an example:



                             Map<QName, Serializable> props = new HashMap<QName, Serializable>();
                              props.put(ContentModel.PROP_NAME, "an link node");
                              props.put(ContentModel.PROP_LINK_DESTINATION, folder red);
                                 // create File Link node
                                 ChildAssociationRef childRef = nodeService.createNode(
                                       parentRef,
                                       ContentModel.ASSOC_CONTAINS,
                                 QName.createQName(namespaceuri, "an link node"),
                                       ApplicationModel.TYPE_FOLDERLINK,
                                       props);

atkiba
Champ in-the-making
Champ in-the-making
Thanks for your answer kaynezhang, I tried that way but I couldn't make it work, but I was able to resolve it doing the following:

<javascript>
var result = node; //Target node
var path = companyhome.childByNamePath("Sites/comex-y-logistica/documentLibrary/Comex y Logistica"); //Where I create the link
pr["cm:name"] = node.name+" link.url";
pr["cm:destination"] = node.nodeRef; //(Alfresco Target Node Reference)
pr["cm:title"] = node.name+" enlace";
pr["cm:description"] = node.name+" link";
linkNode = path.createNode(node.name+ "link.url", "{http://www.alfresco.org/model/application/1.0}filelink", pr);
linkNode.save();
</javascript>