Search code examples
javascriptalfrescoalfresco-webscripts

How to get list of documents with defined value of custom property in Alfresco


We use Alfresco Enterprise 4.2.2.5 platform for our projects.

Our users create contracts in Alfresco folder "../contracts_def" and then start process of approvement. For a example, folder "contracts_def" has the following structure:

Contracts_def (Folder)
   |  
   |---- contract_name1 (Folder)  
   |            |--- contract_name1.docx (main document)  
   |            |--- ext_file1.docx      (document)
   |
   |---- contract_name2 (Folder)
                |--- contract_name2.docx (main document)
                |--- ext_file2.docx      (document)           

Each main document has set of properties, including status of approvement. In Alfresco Node browser property's full name is {httр://www.mytest.ru/model/test/contract/1.0}status.
I'd like to fetch list of documents with status "on-sign" within folder "contracts_def".

I've wrote simple script for running in Java Script Console:

    var rs = search.query
      ({ query:
        "SELECT * FROM cmis:document WHERE CONTAINS('PATH:\"/app:company_home/st:sites/cm:contracts/cm:documentLibrary/cm:contracts/cm:contracts_def//*\"')",
         language:"cmis-alfresco" });
      for (var r in rs)
      { logger.log(rs[r].parent.name + "/" + rs[r].name + "\t" +  rs[r].properties.status); }

There are 3 questions:

1) Script works, but Instead of document's status I get "NULL". How I understand, script doesn't return custom property of documents - {httр://www.mytest.ru/model/test/contract/1.0}status, but I can get only none-custom properties, for example {httр://www.alfresco.org/model/content/1.0}creator.

2) I'd like to fetch list of documents which have only status "on-sign", but script will return all specified properties without filtering.

How can I change code for my requirements?

3) Can I get this information using built-in web-scripts of Alfresco?

Thanks in advance.


Solution

  • It is not clear why you want to use CMIS for this if you are running the code in the server-side JavaScript console which has full access to the JavaScript API and native search.

    Rather than using JavaScript and CMIS, you might find it easier to first just get a query working by using the Node Browser available in the admin console.

    Go to the admin console, then the node browser, and put this in the search box:

    PATH:"/app:company_home/st:sites/cm:contracts/cm:documentLibrary/cm:contracts/cm:contracts_def//*" =test:status:"on-sign"
    

    Make sure "fts-alfresco" is selected.

    Now that you have a working query, you can go back to the JS console and use it in your search.query call.