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

m_guerra
Champ in-the-making
Champ in-the-making
Greetings…

I still haven't figured a way to solve my problem…

Anyone has any ideas? Anything at all would be much appreciated…

Best regards

Marcelo Guerra

zladuric
Champ on-the-rise
Champ on-the-rise
Maybe you can see how these webscripts work and do something with that?

http://wiki.alfresco.com/wiki/3.0_Activities_Developer_Guide#Sample_2:_Calendar_Events

m_guerra
Champ in-the-making
Champ in-the-making
Hey…

Thanks Zlatko… I looked into that and some other things and right now my script is looking something like this:

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

var timestamp = new Date().getTime();
var random = Math.round(Math.random() * 10000);
var event = qwerty.createNode(timestamp + "-" + random + ".ics", "ia:calendarEvent"); //qwerty is the name of my site

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

var fromDate = "2011-03-09";
var toDate = "2011-03-10";

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

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

But I can't seem to create the event… it is giving me this error:
02090119 Failed to execute script 'workspace://SpacesStore/7c6e1b80-ed29-4008-ac30-13e9cfa75dc6': 02090118 ReferenceError: "qwerty" is not defined. (workspace://SpacesStore/7c6e1b80-ed29-4008-ac30-13e9cfa75dc6#25

I'll keep messing around…

Thanks again Zlatko

Best Regards

Marcelo Guerra

zladuric
Champ on-the-rise
Champ on-the-rise
Well qwerty is not a root object in alfresco, they didn't predict you'll be naming your site that Smiley Happy
You do have companyhome object though.

So you gotta get a hold of the site space, something like:

var qwerty = companyhome.childByNamePath("Sites/querty");

Or if you need the actual site (not the site space, the site itself), you need to:
var querty = siteService.getSite("querty");

So use whichever you need.
Hope that helps.

m_guerra
Champ in-the-making
Champ in-the-making
Well many thanks Zlatko  Smiley Very Happy

Right now I can create a calendar event… well kind of… the .ics file is being created in the right place (on the folder calendar of the site "qwerty") but it isn't showing on the calendar itself…

Any thoughts on that?  :roll:

Thanks

Marcelo Guerra

P.S.
My script now looks like:

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

var site = siteService.getSite("qwerty");
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-09";
var toDate = "2011-03-10";

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

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

try
{
  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());
  var data =
  {
    title: params["what"],
    page: json.get("page") + "?date=" + isoDate
  }
  activities.postActivity("org.alfresco.calendar.event-created", siteId, "calendar", jsonUtils.toJSONString(data));
}
catch(e)
{
  if (logger.isLoggingEnabled())
  {
    logger.log(e);
  }
}

zladuric
Champ on-the-rise
Champ on-the-rise
Uh, now I'm totally out of my area. I think you need to post that activity, something like:
activities.postActivity("org.alfresco.calendar.event-created", siteId, "calendar", eventData);

Look how they've done it in event.post webscript. (event.post.json.js).

m_guerra
Champ in-the-making
Champ in-the-making
Hmmm… I get what you mean Smiley Happy

but I can't execute json on the script… and I don't know what they mean by page on: "json.get("page") + "?date=" + isoDate"… do they mean the page on the site, like calendar? I tried putting a simple string instead of the "jsonUtils.toJSONString(data)" but still nothing:

   try
   {
      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());
      var data =
      {
         title: params["what"],
         page: json.get("page") + "?date=" + isoDate
      }
      activities.postActivity("org.alfresco.calendar.event-created", siteId, "calendar", jsonUtils.toJSONString(data));
   }
   catch(e)
   {
      if (logger.isLoggingEnabled())
      {
         logger.log(e);
      }
   }

Thanks

zladuric
Champ on-the-rise
Champ on-the-rise
Ok now I've searched who's calling the event.post webscript from share and it seems it's calendar-view.js (/share/components/calendar). That's a client side javascript.

That seems to put just the word "calendar" in the jsons' "page" field.

So maybe make the last argument just a simple string, something like this: '{  title: "Test title",page: "calendar?date=2011-03-09" }'.

So your call now looks like:

activities.postActivity("org.alfresco.calendar.event-created", "qwerty", "calendar", '{  title: "Test title",page: "calendar?date=2011-03-09" }');

Let me know if it worked Smiley Happy

m_guerra
Champ in-the-making
Champ in-the-making
:roll: hmmmm it doesn't work…  also I tried another way something like:

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 + '" }');

but with no success…

I'll keep in touch in case I find a way…

Many Thanks Zlatko   Smiley Happy