Search code examples
javascriptalfresco

Alfresco get the path of documents using CMIS



I'm trying to fetch document objects from Alfresco Community edition,I need the documents path, while i use

SELECT * FROM cmis:document where ''

but i thing the cmis:document namespace doesn't return the path, i was wondering if there is a way to include the path.
PS : i can only use JAVASCRIPT with cmis queries


Solution

  • Instead of a CMIS query you should just fetch the object by URL using its object ID, then grab the path. The browser binding, which is easily invocable from JavaScript, supports this.

    For example, suppose I have a file named "test-1.txt" sitting in a folder called "/test" with an Alfresco object ID of:

    workspace://SpacesStore/1fb2d9cf-11ca-47c2-94b4-cf72de8f9b92
    

    I can use this URL:

    http://localhost:8080/alfresco/api/-default-/public/cmis/versions/1.1/browser/root?objectId=workspace://SpacesStore/1fb2d9cf-11ca-47c2-94b4-cf72de8f9b92&cmisselector=parents&includerelativepathsegment=true
    

    To return JSON that includes:

    {
        "id": "cmis:path",
        "localName": "path",
        "displayName": "Path",
        "queryName": "cmis:path",
        "type": "string",
        "cardinality": "single",
        "value": "\/test"
    }
    

    Which contains the path.

    You can shorten up the JSON significantly by also adding "&succinct=true"