Create WebScript in Alfresco

In the previous post we have learned about what are webscripts and its role in Alfresco. In this post I will explain how to create a simple webscript in Alfresco. We are going to create Alfresco JavaScript based webscript. Here we are creating webscript which fetch all the document of particular type from repository and return html file with all those properties.

Step1:

Create WebScript Description file getDocs.get.desc.xml

<alfresco-config>
   <config evaluator="string-compare" condition="WebFramework">
      <web-framework>
         <defaults>
            <page-type>
               <id>login</id>
               <page-instance-id>custom-login</page-instance-id>
            </page-type>
         </defaults>
      </web-framework>
   </config>
</alfresco-config>

Step2:

Create Webscript  javascript controller file getDocs.get.js

<page>
   <template-instance>custom-login</template-instance>
   <authentication>none</authentication>
</page>

Step3:

Create Freemarker Template File getDocs.get.html.ftl

<page>
   <template-instance>custom-login</template-instance>
   <authentication>none</authentication>
</page>

 Step4:

Upload all three files under you alfresco installation under following path

CompanyHome>Data Dictionary> Web Scripts Extensions

Step5:

Restart the server hit this url

http://<host>:<port>/alfresco/service/fetchdocs

You are good to go to test above webscript you need to hit this url in your browser you will see list of documents of custom content type.

This type of webscripts is very powerful tool to expose alfresco webscript to external application. It is lightweight. It is easy to create and deploy and update. You can deploy your changes on the fly without restarting the server that is the best thing about this type of webscript.

Looking for quality Alfresco Hosting?  Look no further than Arvixe Web Hosting!

Tags: , , , , , | Posted under Alfresco | RSS 2.0

Author Spotlight

mitpatoliya

mitpatoliya

I love opensource technologies working with those technologies from the time I have stepped in to the Software Industry. Alfresco CMS is my area of expertise. I have worked on various complex implementations which involved integration of Alfresco with other technologies, extensively worked with JBPM workflows and Webscripts.

2 Comments on Create WebScript in Alfresco

  1. deepa says:

    i have created the webscript to fetch the custom content type document using the specified aspect type but it was not working could you please help in this.
    docdetails.get.desc.xml

    Document Details
    Searches document(s) and displays details of allthe documents.
    /com/infoaxon/docdetails

    user
    required

    docdetails.get.html.ftl

    Found Documents with name: ${TYPE}

    Name
    Create Date
    Creator
    Size (bytes)

    ${c.name}
    ${c.properties[“cm:created”]?datetime}
    ${c.properties[“cm:creator”]}
    ${c.size}

    Search Parameter not provided.

    docdetails.get.js

    function main()
    {
    var TYPE = args.TYPE;
    var qry = (“TYPE:\”{http://www.someco.com/model/content/1.0}webable);
    var docs = search.luceneSearch(qry);
    model.docs = docs;
    model.TYPE = TYPE;
    }
    main();

    in node browser i can see my aspect type as:{http://www.someco.com/model/content/1.0}webable

    • mitpatoliya mitpatoliya says:

      Hi Deepa,
      Type and Aspects are different things. You are using type query instead of that you need to use Aspect query.
      ASPECT:”{http://www.someco.com/model/content/1.0}webable”

      Also in FTL file you need to iterate through list of docs to get properties.

      < #list docs as c>
      < #if c.isDocument>

      ${c.name}

      something like this

Leave a Reply

Your email address will not be published. Required fields are marked *


6 − 4 =

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>