cancel
Showing results for 
Search instead for 
Did you mean: 

Need help on best practices

sgartner
Champ on-the-rise
Champ on-the-rise
Hi all and thanks in advance for your help.

I am using Alfresco 3.2 and I am looking for advice on the best plan for passing documents around.  It seems like there are two ways: by path and by noderef.  There also seems to be something called the "current document" which I really don't get.  I am writing links (buttons, calls from AJAX code, whatever) that will go to web scripts which will edit certain aspects, manage workflow, etc. on a passed document.  So, it seems to me that I will be passing some reference to a document to each of these scripts. 

The nodeRef seems like an obvious choice since (I assume) it is fixed in size and won't have any unexpected symbols (apart from colon and slash) and apparently I can simply do new Node(nodeRef) to get the node. 

However it seems like a lot of people are using the full path to the document and then using userhome.childByNamePath(documentPath) to find the document's node.  The path, however, seems like it could potentially be very long indeed, and could have any random foreign character or symbol in it, and so I would have to use POST methods to send this to the script.  This doesn't seem like the best plan.

And maybe there is something fundamental that I'm missing, because when I look at some of the built-in web scripts they seem to not have any parameters passed in yet clearly they do work to a document.  Maybe they are using this "current document" thing that I've read references to, but haven't yet read anything clearly describing what this is.

Note that I'm just learning Alfresco, so I may be missing something fundamental here.

Thanks,
1 REPLY 1

sgartner
Champ on-the-rise
Champ on-the-rise
I got this from a friend:

For what it’s worth, I have settled down on doing the following:
    1.   I use noderef when ever I can. Especially when a doc ref as an argument between web scripts. Noderef, as you state, is shorter, and it remains the same even if the document moves. The Utilities object has a handy routine to get the ScriptNode object that has a given noderef (see http://wiki.alfresco.com/wiki/3.2_JavaScript_API#Utility_Functions) utils.GetNodeFromString(<noderef>).
    2.   I do use paths, and childByNamePath(), or childrenByXPath() when I want to do simple searches, or grab a directory to iterate through.
      a.   There are cases where I know the directory name I want to iterate through, but not the noderef.
      b.   There are rare cases where I know the filename and where it is, but not the noderef.
      c.   Finally, there are cases where I want to search for files matching a given criteria.
    3.   I have written only a couple of small scripts that act as either document actions, or as view templates for a document. In these two cases, Alfresco sets the ‘document’ object for me. However, the bulk of the time, the scrip is not working on a specific document, so the document object is not set.