cancel
Showing results for 
Search instead for 
Did you mean: 

Simple script to get Calendar events.[Solved]

michaelc
Champ on-the-rise
Champ on-the-rise
This is in WCMQS but it's the same as the share elements.

Requirement: On a page show all up coming events with a given site.
Seems simple the following URL will give me that result.
   http://localhost:8080/share/proxy/alfresco-feed/calendar/eventList?site=content&format=json

  So I expected the following would work.

    var connector = remote.connect("alfresco");
   var result = connector.get("/alfresco-feed/calendar/eventList?site=content&format=json")

   //             Also tried
  //    var result = remote.call("/alfresco/service/calendar/getCalendarEvent");

   if (result.status == 200 && result != "{}")
   {
      prefs = eval('(' + result + ')');
     
      // get the dates
      for (var i = 0; i < prefs.properties.length; i++) {
           objArray = prefs.properties[i].value;
           for (var i2 = 0; i2 < objArray.length; i2++) {
                 resultArray.push(objArray[i2].uri)
           }

      }
      model.result = resultArray;

   }
   model.status = result.status
  

The result is not authorized or not found.
  I just don't understand how - seems simple but I seem to have missed something.
2 REPLIES 2

davidcognite
Star Contributor
Star Contributor
Hello,

I've had a look and there were a few issues with the code you posted.

The result you were getting was likely to be a 404 - the "/alfresco-feed" part of the URL isn't necessary.

You were also trying to process the result as an array (you can't do .length on an object, you need to loop using the "for x in obj" construct); that API call actually returns the result as an object, indexed by date (as a MM/DD/YYYY string). It's not the friendliest format, but I'm sure there is a good reason we did it that way!

Unless you actually want the results in that format, I'd recommend you use the following call:
http://localhost:8080/share/proxy/alfresco/calendar/events/content/user 
(where "content" is the shortname for your site).
This returns a format that is much easier to consume: an object containing an "events" array.

You can then use the follow to get and return that array:

var connector = remote.connect("alfresco");
var result = connector.get("/calendar/events/content/user");

if (result.status == 200 && result != "{}")
{
   resultObj = eval('(' + result + ')');
   model.result = resultObj.events;
}
model.status = result.status

You may want to abstract out the site name rather than hard code it ("content") in the URL.

Hope that helps.

David.

michaelc
Champ on-the-rise
Champ on-the-rise
the issue is this is not in share and is in WCMQS.
this uses a different config file you need to modify surf.xml in wcmqs
add the following
    <config evaluator="string-compare" condition="Remote">
        <remote>
            <endpoint>
                <id>alfresco-webscripts</id>
                <name>Alfresco Webscripts</name>
                <connector-id>http</connector-id>
                <endpoint-url>http://localhost:8080/alfresco/service</endpoint-url>
                <identity>declared</identity>
                <username>admin</username>
                <password>admin</password>
            </endpoint>
        </remote>
    </config>

it now works like a champ