Updating all instance of a recurring event in Google Calendar API - google-calendar-api

What is the proper way to update all (or a subset) of the instances of a recurring event? Also related: how do you, given the id of the original event, get the instances of that event?

If you want to update just a subset of recurring events, then you need to set singleevents = true when running your query to retrieve the initial list of events. In PHP you'd do something like this
$gdataCal = new Zend_Gdata_Calendar($client);
$query = $gdataCal->newEventQuery();
$query->setUser('default');
$query->setVisibility('private');
$query->setProjection('full');
$query->setOrderby('starttime');
$query->setStartMin($startDate);
$query->setStartMax($endDate);
$query->setSingleEvents('true'); //get recurring events as a series of single events
$eventFeed = $gdataCal->getCalendarEventFeed($query);
foreach ($eventFeed as $event) {
//do stuff with $event
}

I tried with updating all recurrence event ,it is working.Initially I created one Recurring event like weekly on Monday from 2016-02-25 to 2016-03 25 and It is created 6 instances for that recurring period.During updating what I tried is,
1.First I assigned to Recurrence field ,
"recurrence":["RRULE:FREQ=WEEKLY;COUNT=18;BYDAY=TU"] (Updating like weekly on Tuesday)
2.after that I fetching available lists using list google api.here I used Single Events: false(in the sence it will give only main recurring event not all instances)
3.after I used update event to update like passing auth,eventId and calendarId: "primary" and resource:updated event array
then it is done .It is updating the instances as Weekly on Tuesday.
I hope it will help to someone.

To update all you just change the relevant properties for the event, leaving the recurrence and recurrence exceptions strings intact. Not sure that you can easily modify a subset, as this would require converting the recurring event into multiple new events depending on the subset.
For the second part or your question, according to the API docs:
Specifically, each recurring event is
represented by a
element in the result feed, and each
of those elements includes a
element for each occurrence of that
event that falls between the start
time and the end time. Looking at
elements is much simpler
than parsing recurrences and
exceptions yourself.
However, I've never been able to find that magic "when"... so I've ended up parsing the recurrence and recurrenceexceptions strings - if you find the answer to that one, let us all know!

For anyone with this issue I also spent some time trying to figure this out. Basically when you get your CalendarEventEntry list you need to check for each calendarEventEntry if it has an originalEvent (calendarEventEntry.getOriginalEvent()). This basically tells you there is another event (which you may or may not have already processed) that needs to swapped with the information for this current calendarEventEntry.

Related

How can I only fire a tag from Monday to Friday 09.00-17.00?

We only want to show our live chat tag Monday to Friday, from 09.00 until 17.00. Is this possible with Google Tag Manager please?
Thanks!
Preferred solution
The best solution is probably to get the current date on the server side and push to the datalayer a variable that determines whether the chat tag should be triggered or not depending on this date.
Alternative
The alternative is to retrieve the date on the client side which won't be 100% reliable. In order to use this solution, you need to create a Custom Javascript variable with the following code (replace "America/New_York" by your business' timezone) :
function (){
const currentDate = new Date(new Date().toLocaleString("en-US", {timeZone: "America/New_York"}));
const day = currentDate.getDay()
const hours = currentDate.getHours()
return day > 0 && day < 6 && hours >= 9 && hours < 17
}
Then, trigger your chat tag only when this variable's value is "true".
If you want to get a consistent, reliable date, ListenLayer.com returns a timestamp with every data dataLayer push. The time can appear in a single account timezone based on your account settings, so if you align your ListenLayer timezone to your chat time zone it will work.
You can then write rules in the platform to determine if the time returned should allow for chat. You will output a yes/no into a new data layer variable based on the rule. Then you will register this variable in GTM and use it to determine if the chat tag should fire.
Here is the process I would use at a high level
Create an account and set the account time to match your chat timezone
Turn on the User Source Listener and all it's features,
enable it to push on every page load This will push the user's traffic source into the data layer, along with a bunch of other structured data on each page load. You could use another listener, but this one will allow us to ensure it pushes on every page load (container load) so that GTM will know on every page load whether to trigger the chat script.
Create a custom data layer variable called chatTime. We will write a rule in ListenLayer to push a yes or a no into this variable based on the time that is returned in the userSource data layer event. This will happen in real time, in the same event in the data layer.
Publish everything in listenlayer and then go to your website with the console open (the data layer is written there for ease). You'll see the userSource dataLayer event in the console on every page load. It will contain an eventTimestamp. You want the data that is inside the listenlayerAccountTime node because it will match your ListenLayer timezone, which should match the timezone you operate your chat hours from (or if all of this is based on the user's time zone, use that one to be localized to them). You will need to focus on these two variables that are automatically provided because we will write a rule based on them in step 5:
sourceAutomaticValues.eventTimestamp.listenlayerAccountTime.time.timeOfDay
sourceAutomaticValues.eventTimestamp.listenlayerAccountTime.time.dayOfWeek
Here is a visual showing those variables I have given a path to above. One of the day of the week and one is the time of day.
Inside ListenLayer, under the User Source listener you will create two rules, they will be lookup table rules. The first rule will run first, then the second. If a match is found, they will stop. This means we can write the first rule to basically just look at the day of the week and set chatTime to no if the value is Sat or Sun. The second rule will then focus on the time of the day since this rule will only be reached if it is not Saturday or Sunday. In this rule we will look at the first part of the timeOfDay variable using simple ReGex. Our rule has 24 rows for each hour of the day and will return a yes only for the hours you are open for chat. Certainly this rule could be made simpler with some additional regex, but this gives a better illustration. There is an import export so you could spin up the 24 row rule in a csv file and import it.
After you save and publish this simple logic, your website will have a value in the data layer telling google tag manager whether chat should be on. It will appear in the data layer every time the userSource event is pushed, which is every page load.
I assume things are easy from here. You would create a data layer variable inside GTM referencing sourceCustomValues.chatTime You'll also create a custom event trigger referencing userSource and only firing if chatTime = yes. Then you will set your chat tag to fire on this trigger.

Deleting intermediate record from Google Calendar recurring event

I am working with Google calendar recurring events. I created a recurring event and by using GData library, in response i get the the perimeters "COUNT", "FREQ" , "UNTIL" etc... where COUNT=5.
The problem is, when I delete an instance from this recurring event(total instance are 5 in this case), 4 instances are left in google calendar. but in response COUNT is still 5, it should be 4 now. Also in response i am not getting any details about that deleted instance.
Can any one help me in this regards.
I am very thankful in advance!!!
waiting for your reply!
This is working as intended. If the count indeed changed that would mean that the last instance should not be there anymore. While you could have deleted the second instance. In the v3 API the deletion of the second instance will be represented by an event with status=cancelled and "recurringEventId" + "originalStartTime" set to point to that specific instance.
There is a handy instances() call if you want to see all the instances of a recurring event.

Show only Months with Events In them?

Would there be a way to limit the next/prev buttons to only show months with events registered in them? We have courses that fill up and I don't want users to have to fast forward through blank months where there is no availability of events. I'm also including holiday events from the basic google public holidays calendar and don't want to include those events.
As long as I know, this option does not exist in FullCalendar yet.
If you are retrieving events month by month:
You can bind fullcalendar's Next and Previous events to a new function. Inside this function, get the events and if there is no events, your function must call Next or Previous again.
If you are retrieving all events at once
You can bind fullcalendar's Next and Previous events to a new function. Inside this function, get all the events and look for the first date out of the current month. Set fullcalendar's current date for that month and refresh it.

Already save has_many relation in getCMSField_forpopup records in appearing again in every new records in SilverStripe

I have one getCMSField_forpopup form for an event. I made another popup inside that to give multiple dates to that event(using has_many relation). When I give date 2 different dates/times to event "A" and then after saving event "A", I open main getCMSField_forpopup to enter details of another event "B" then I see dates/times (complextablefield) already there which were actually meant to appear in event A's detail not in event "B". I want to see those only with A not with every new event. How can I make that possible ?
Your problem is that you enter Dates for 1 Event, but then you can see this Dates on every single Event?
to me this sounds like either your Event has no ID at this time and therefore a query on Dates "WHERE EventID = x" does not work, or your Dates get saved without the ID of the Event
You could simply check your database if your Dates have the ID of an Event set.
If the ID if the Event is 0, then the issue is that you are not saving the event ID, this either means that:
you have created the Dates before saving the Event, in this case the solution is just saving the Event before you add Dates, you could also hide the Dates field when it has not been saved, see below the $this->isNew() stuff
or silverstripe fails to save the EventID, in this case you could fix it by adding a hidden field to your getCMSFields_forPopup of the Date and save the Event ID there, but its gonna be a little tricky getting this ID into the popup
if this is not the issue, then the problem is that when you create a new Event it has no ID, and therefore can not filter by ID, you can simply do this inside your getCMSFields_forPopup of the Event:
if (!$this->isNew()) {
// add your ComplexTableField for Dates here so it only
// gets added if this record has already been saved
}
But actually I would recommend using nested DataObjectManager (a DataObjectManager inside a DataObjectManager)(see tutorial on youtube: http://youtu.be/eeXOTlXFmQQ), DataObjectManager does all that work for you, so this problem should not occur.
It only displays the DataObjectManager for Dates if you have already saved the Event once, otherwise it tells the user that he needs to save it first.
And it also sets the Event ID on the Dates for you
Or, even better, you could upgrade to SilverStripe 3, where you can use GridField.
GridField works way better then DataObjectManager and looks a lot nicer.

CRM 2011 Workflow Condition Issue

I have created a simple workflow in CRM 2011 which checks a field value in one entity and creates a new record in a different entity. Sometimes however, the creation doesn't occur, it just seems that the condition is not met when it should be.
Consider an entity called "Car" which has a text field called "Task". This Task field will always be saved with 1 of 4 possible values: "", "Add", "Change", "Delete".
This value is used to determine how the workflow should process.
The workflow is set to fire when a different field is changed - "Driver".
The workflow is setup like this...
- Condition
- If "Task" == "Add"
- create new record
- Else if "Task" == "Change"
- create new record
- Else if "Task" == "Delete"
- create new record
- Reset "Task" to ""
NOTE: the created record is using different values depending on "Task"
I can see that the workflow is always fired when expected, and both the "Condition" and the "Reset" are processed. The problem is that sometimes (although, not so far today) no record is created - this suggests that none of the IF conditions are met. However, I have no reason to explain why. I can see that the field "Task" is always set as expected prior to the save (exact spelling/casing and all)
So, are there any known issues with CRM workflows that could explain this? Is there a more indepth way to debug these issues? (i.e. check the value of "Task" at time on "Condition" checks)
I am wondering is it possible that the "Reset" part of the workflow is somehow being processed before the condition? and there for the condition is checking a blank field.
Any help will be greatly appreciated, Thanks
Unfortunately, I have not experienced this issue again since the first time when I created the workflow.
However, some good techniques where offered in comments as to how this sort of issue could be debugged - thanks to those people!
Firstly, you can turn on Entity Auditing which will help you track down what is going wrong.
Another option would be to send an email from the workflow with the current data values for debugging, or add a final "else" clause to send emails when none of the conditions have been met (perhaps a good fail safe addition to have even when it does seem to all be working) - I like this second option as it is more "out of the box" thinking ;)
Anyway here you can find information on sending emails from within a CRM workflow

Resources