javascriptalfrescoalfresco-sharealfresco-webscripts

How to get NodeRef of specific folder in Alfresco share using javascript?


I am working on Alfresco project for some time. This is my first time facing Alfresco, so the help will be useful. I need to get a nodeRef of specific folder from one site using JavaScript. I have not prepare any code, sorry for that, but I haven't idea so far how to start.

Using companyhome won't work for me, because I work in Alfresco Share, and Share does not support objects from Repository side, am I right?

For example, if I have site "Documents", inside site I have folder "Report", how to get to the Report folder using javascript, and how to list children of folder Report?

Thanks in advance!


Solution

  • I suggest you install js-console first, which gives you an interactive javascript console in Share's Admin-Tools. The js-console supports autocomplete (ctl-space) like a IDE and is the best way to learn and implement js in Alfresco.

    There is no reason why companyhome should not work. Maybe your Alfresco is configured to have a different mount point instead of companyhome?

    You could use different js apis to get the reports nodeRef:

    1. childByNamePath from companyhome
      var reportsNode = companyhome.childByNamePath('/Sites/documents/documentLibrary/Reports');
      
    2. siteService API
      var docLib = siteService.getSite("documents").getContainer('documentLibrary')
      if (docLib){
          var reportsNode = docLib.childByNamePath('Reports')
          if (reportsNode){
              logger.log("Reports folder: " + reportsNode.displayPath + '/' + reportsNode.name);
          }
      }
      

    Once you have the reportsNode you could iterate over the childs and do what you want to do:

    for each (var node in reportsNode.children){
        logger.log(node.displayPath + '/' + node.name)
    }