cancel
Showing results for 
Search instead for 
Did you mean: 

Share Calendar Script

m_guerra
Champ in-the-making
Champ in-the-making
Hi,

As you may have noticed I'm a newbie here, so I hope I'm not posting this topic on the wrong forum, and that this question wasn't answered before, so correct me if Im wrong please. Smiley Happy

I've implemented a script that on the arrival of a new item on a data list, assigns a Review and Approve workflow to a user, then by modifying the review_processdefinition.xml on approval of the item it moves the item to another folder. What I need to do is to create another rule on that folder that executes a script, to gather the values start date and end date from the list item to create an event on the calendar… but… I don't know if this is possible, and I don't even know if the script is made the same way like "actions.create("calendar-event")" or something like this. If you guys could point me the right way or tell me where to look for writing scripts it would be very helpful.  :roll:

Thanks in advance

Marcelo Guerra

P.S.
All that I've acomplished so far was only by searching the web and "using/adapting" other peoples code, as I said I'm new to Alfresco and programming and I know nothing about the way Alfresco is designed.  :?
13 REPLIES 13

zladuric
Champ on-the-rise
Champ on-the-rise
Hmm, seems I had you on the wrong track. I get the result in site activities dashlet when I execute the code:
activities.postActivity("org.alfresco.calendar.event-created", "demo", "calendar", '{ title: "Test title",page: "calendar?date=2011-03-09" }');

So my Site Activities shows this activity.

But the event is not shown in Site Calendar Smiley Sad
13:00, Mar 9, 2011
13:27
Test title calendar event created by Administrator

m_guerra
Champ in-the-making
Champ in-the-making
Hmmm I don't even get anything on the site activity dashlet…

Well I'm gonna go lunch and when I come back I'll keep working on the problem…  Smiley Very Happy

I'll keep in touch…

Regards

Marcelo Guerra

m_guerra
Champ in-the-making
Champ in-the-making
Ok… so my script now is looking like this:

<import resource="classpath:/alfresco/templates/webscripts/org/alfresco/slingshot/calendar/lib/calendar.lib.js">

var siteId = "qwerty";
var site = siteService.getSite(siteId);
var calendar = getCalendarContainer(site);

var timestamp = new Date().getTime();
var random = Math.round(Math.random() * 10000);
var event = calendar.createNode(timestamp + "-" + random + ".ics", "ia:calendarEvent");

event.properties["ia:whatEvent"] = "Event";
event.properties["ia:whereEvent"] = "Here";
event.properties["ia:descriptionEvent"] = "An event";

var fromDate = "2011,03,10,00,00";
var toDate = "2011,03,15,00,00";

var from = new Date(fromDate);
event.properties["ia:fromDate"] = from;

var to = new Date(toDate);
event.properties["ia:toDate"] = to;
event.save();

var pad = function (value, length)
{
   value = String(value);
   length = parseInt(length) || 2;
   while (value.length < length)
   {
      value = "0" + value;
   }
return value;
};

var isoDate = from.getFullYear() + "-" + pad(from.getMonth() + 1) + "-" + pad(from.getDate());

activities.postActivity("org.alfresco.calendar.event-created", siteId, "calendar", '{ title: "Test title", page: "calendar?date=' + isoDate + '" }');

It is able to create an .ics file on the correct place, but that's all it can do… the calendar event doesn't show up, and the site activities dashlet shows no recent activities…

Any more ideas on what can be causing this, as I'm able to create the .ics file on the right place and I'm not getting the event to show up!?

Regards

Marcelo Guerra

m_guerra
Champ in-the-making
Champ in-the-making
Ok I got it working now… the problem was the date format…

So if anyone has the same problem here is the working code:

<import resource="classpath:/alfresco/templates/webscripts/org/alfresco/slingshot/calendar/lib/calendar.lib.js">

var siteId = "qwerty";
var site = siteService.getSite(siteId);
var calendar = getCalendarContainer(site);

var timestamp = new Date().getTime();
var random = Math.round(Math.random() * 10000);
var event = calendar.createNode(timestamp + "-" + random + ".ics", "ia:calendarEvent");

event.properties["ia:whatEvent"] = "Event";
event.properties["ia:whereEvent"] = "Here";
event.properties["ia:descriptionEvent"] = "An event";
event.properties["ia:docFolder"] = "";

var fromDate = "March 10, 2011 00:00:00";
var toDate = "March 15, 2011 00:00:00";

var from = new Date(fromDate);
event.properties["ia:fromDate"] = from;

var to = new Date(toDate);
event.properties["ia:toDate"] = to;
event.save();

var pad = function (value, length)
{
   value = String(value);
   length = parseInt(length) || 2;
   while (value.length < length)
   {
      value = "0" + value;
   }
return value;
};

var isoDate = from.getFullYear() + "-" + pad(from.getMonth() + 1) + "-" + pad(from.getDate());

activities.postActivity("org.alfresco.calendar.event-created", siteId, "calendar", '{ title: "Test title", page: "calendar?date=' + isoDate + '" }');

All I need to do now is to change the "hardcoded values" of the dates and name of the event, to the ones that come from the metadata from the file that arrived to the folder…

I'll be posting the news…

Regards

Marcelo Guerra