AnsweredAssumed Answered

Accessing Datalists from WCMQS

Question asked by simon.white on Jun 2, 2011
Latest reply on Jun 5, 2011 by bremmington

I've got a bunch of information stored in Alfresco Share datalists
(out-of-the-box 'Event' type datalists as it happens) which I want
to use to populate some web page fragments managed by Web Quickstart.

I'm currently using the following method to get data out of the datalists,
which works fine but I feel like I'm missing a trick - datalists are integral
enough to the demonstration websites provided with WCQMS that it feels like there
should be a more direct method of accessing them.

Anyway, what I'm doing is this:

Datalists are just nodes within the repository so I can access them using CMIS. 
The service at /cmis/p/Sites/{siteName}/dataLists/children lists all the datalists,
and I can use a different instantiation of the same service,
/cmis/p/Sites/{siteName}/dataLists/{name}/children to get me the entries in an
individual data list.  This service only provides atom responses by default, so I
use the following ftl template to return a (incomplete but sufficent) JSON response
instead, as this is easier to work with in Javascript webscripts:

<#escape x as jsonUtils.encodeJSONString(x)>
  children: [
    <#list results as node>
            author:         "${!""}",
            id:             "${}",
            name:           "${}",
            created:        "${xmldate(}",
            title:          "${['cm:title']!""}",
            updated:        "${xmldate(}",
            nodeDetails:    "${node}",
            eventLocation:  "${['dl:eventLocation']!""}",
            eventStartDate: "${xmldate(['dl:eventStartDate'])!""}",
            description:    "${['cm:description']!""}"
     <#if node_has_next>,</#if>

The last complication is that datalist names are actually system-generated UUIDs. 
The human-readable bit is the title, so we need to look up the UUID from the title in
order to reach our target datascript.

A simplified version of the server-side javascript I'm using in wcmqs, therefore, is:

function getEventListName(title) {
   var conn = remote.connect("alfresco-webscripts");
   var uri = "/cmis/p/Sites/webcontent/dataLists/children?format=json";
   var responseText=conn.get(uri).response;
   var allLists=(eval('(' + responseText + ')')).children;
   for (var i=0; i < allLists.length; i++)   {
      if (allLists[i].title==title) {
         return allLists[i].name;
   throw "No list with the ID: "+list+" could be found";

function getEventList(name) {
   var conn = remote.connect("alfresco-webscripts");
   var uri = "/cmis/p/Sites/webcontent/dataLists/"+name+"/children?format=json";
   var events=(eval('(' + conn.get(uri).response + ')')).children;
   return events;

As I say, the above works fine and pushes the relevant events details into the freemarker model for
rendition, but it feels very overworked.

Is there some simple API call that I'm missing here?

Thanks in advance,