create link to node or folder using js

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Active Member II

create link to node or folder using js

Hi all.

in 5.2 how can i create a link to a document (or a folder) that when i delete the source node, it will also be deleted.

I have seen

https://community.alfresco.com/thread/149153-create-a-link-to-a-node-file-or-folder#comment-617799 

 and DocumentLinkServiceImpl.java

alfresco-open-mirror - Revision 138279: /alfresco/HEAD/root/projects/repository/source/java/org/alfr... 

but i cannot complete such a task.

Thank you in advance.

4 Replies
Highlighted
Professional

Re: create link to node or folder using js

What you are describing is the out-of-the-box behavior for links in Alfresco. If you create a document, then do a Copy, you can choose "Create Link" when you pick the destination.

If you then go delete the original document, the link is also deleted.

Is this the functionality you are looking for or is it something different?

Highlighted
Active Member II

Re: create link to node or folder using js

yes this functionallity we want to reproduce using javascript.

if we use:

var pr = [];
pr["cm:name"] = "targetName.jpg.url";
pr["cm:destination"] = "workspace://SpacesStore/76c17fe2-93f9-4293-a989-e50c4c1e01e4"; (Alfresco Target Node Reference)
pr["cm:title"] = "targetName.jpg";
pr["cm:description"] = "targetName.jpg";
linkNode = space.createNode("targetName.jpg.url", "{http://www.alfresco.org/model/application/1.0}filelink", pr);
linkNode.save();

as suggested in a previous post, the assosiasion is not created, add the aspect ASPECT_LINKED is not added to the target node (while enabling and dissabling the ContentModel.ASPECT_AUDITABLE behaviour).

Highlighted
Professional

Re: create link to node or folder using js

You can add the linked aspect yourself. So, taking your code, and adding a couple of variables for the doc and the space, this works:

var doc = search.findNode("workspace://SpacesStore/af65018d-dabb-4a83-ac22-007dd99ff361");

var space = search.findNode("workspace://SpacesStore/6513e985-ce14-4002-bee9-0a60279f44b0");

var pr = [];
pr["cm:name"] = "test1.txt.url";
pr["cm:destination"] = doc.nodeRef.toString();
pr["cm:title"] = "test1.txt";
pr["cm:description"] = "test1.txt";
linkNode = space.createNode("test1.txt.url", "{http://www.alfresco.org/model/application/1.0}filelink", pr);
linkNode.save();

doc.addAspect("app:linked");
doc.save();

Highlighted
Active Member II

Re: create link to node or folder using js

Noticed that when creating links with the above code, i get the warning:

WARN  [web.scripts.ActionEvaluatorHelper] Evaluator 'null' not found.

when I browse to the folder that the link exists. Any ideas why?

Edit: ok, the above warning i am getting also when i create the link from share interface.