alfrescoalfresco-webscripts

Alfresco search by xpath in the javascript console


I've trouble starting to learn how to perform queries in alfresco xpath. I'm working in the alfresco javascript console as a prototipization and for proof of concept.

The final goal is to find all children of a node of a certain type (in my case, 'doc:doc'), or, as an alternative, I'd like to exclude the thumbnails (renditions).

assuming that the node is called "node", I already tried the following: node.childrenByXPath('*//.') //the search works, but no filter on type ... but none of these works node.childrenByXPath("*//[@type='doc:doc']") node.childrenByXPath("*//.[TYPE='doc:doc']") node.childrenByXPath("TYPE='doc:doc'") node.childrenByXPath("+TYPE='doc:doc'")

Can anyone help or at least point me a good tutorial on this topic? i've followed https://hub.alfresco.com/t5/alfresco-content-services-hub/search-documentation/ba-p/289935 but there are no examples on how to specify the type of a node

thanks


Solution

  • childrenByXPath only filters on the PATH (check node browser for the "Primary Path" on a node to see how a qname path looks like). There is no Type on the qname path.

    You may want to use the search API instead:

    var def =
    {
    query: "PATH:'"+ node.qnamePath +"/*' AND TYPE:'doc:doc' AND !TYPE:'cm:thumbnail'",
    language: "fts-alfresco"
    };
    var results = search.query(def);
    print(results);