I need add remind about appointment before end date, not start date.
This appointment's creation
private async void AddFavoriteTenderEndDateToCalendar(MyEvent event)
{
var appointment = new Appointment();
appointment.StartTime = new DateTimeOffset(event.StartDate);
appointment.Duration = event.EndDate - event.StartDate;
appointment.Subject = "blahblah";
appointment.Reminder = TimeSpan.FromDays(1);
var appointmentId = await AppointmentManager.ShowEditNewAppointmentAsync(appointment);
}
Appointment have not property EndTime and instead I calc duration appointment.Duration = event.EndDate - event.StartDate;
How can I add reminder before event.EndDate?
Related
In my mind, the script below takes a form submission gathered on a sheet and books it into a calendar (calId). In reality, however, the script falls apart at var event = thisCalendar.createEvent(:
Exception: Invalid argument: booker.
function calendarUpload() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Form Responses 1");
var Avals = ss.getRange("A1:A").getValues();
var lastRow = Avals.filter(String).length;
Logger.log(lastRow);
for (var i = 2; i <= lastRow ; i++) {
var approvalStatus = sheet.getRange(i,1).getValue();
var name = sheet.getRange(i,8).getValue(); //Event name.
var description = sheet.getRange(i,9).getValue(); //Event description, agenda.
var date = sheet.getRange(i,5).getValue(); //Event date.
var formattedStart = Utilities.formatDate(new Date(date), 'Europe/London', 'MMMM dd, yyyy');
var startTime = sheet.getRange(i,6).getValue(); //Event starting time.
var formattedSTime = Utilities.formatDate(new Date(startTime), 'Europe/London','hh:mm');
var endTime = sheet.getRange(i,7).getValue(); //Estimated end time of event.
var formattedETime = Utilities.formatDate(new Date(endTime), 'Europe/London','hh:mm');
var guests = sheet.getRange(i,15,1,10).getValues(); //Event guests by email address.
var staffMember = sheet.getRange(i,10).getValue(); //Meeting with... Determines Calendar ID (CalID).
var calId = sheet.getRange(i,11).getValue(); //Calendar.
var booker = sheet.getRange (i,3).getValue(); //The person booking the meeting.
var bookerEmail = sheet.getRange(i,4).getValue(); //Email booker, adds to guest list.
var eventStatus = sheet.getRange(1,1,i,12).getCell(i,12);
//Create eventName based on reason for meeting.
if (name == "one-on-one"){
var title = "ℳ " + booker + " and " + staffMember;
} else {
var title = name
}
Logger.log(eventStatus);
Logger.log(title);
Logger.log(formattedStart);
Logger.log(formattedSTime);
Logger.log(formattedETime);
Logger.log(guests);
var startDateandTime = (formattedStart+" "+formattedSTime);
var endDateandTime = (formattedStart+" "+formattedETime);
Logger.log(startDateandTime);
if (approvalStatus == "Approved" && eventStatus.isBlank()){
var thisCalendar = CalendarApp.getCalendarById(calId);
Logger.log('calId: '+calId);
Logger.log(thisCalendar );
var event = thisCalendar.createEvent(
title,
new Date(startDateandTime),
new Date(endDateandTime),
{guests: guests && bookerEmail, description: description});
Logger.log('Event Series ID: ' + eventSeries.getId());
var setEventStatus = sheet.getRange(i,12).setValue('Event Series ID: ' + event.getId());
} else {
Logger.log("No Events Found");
}
}
}
The logs seem to show that things go smoothly. Is there anything that you'd do differently? What can I do about the Exception error?
Example sheet.
We want to receive change notifications from our user's Outlook calendars. We'd like to limit those notifications to only those calendar items that contain our custom property.
CODE WHICH CREATES CALENDAR EVENT
private static async Task<Event> CreateAppointmentAsync(GraphServiceClient graphClient)
{
var newEvent = new Microsoft.Graph.Event
{
Subject = "Test Calendar Appointmnt",
Start = new DateTimeTimeZone() { TimeZone = TimeZoneInfo.Local.Id, DateTime = "2020-11-21T21:00:00" },
End = new DateTimeTimeZone() { TimeZone = TimeZoneInfo.Local.Id, DateTime = "2020-11-21T22:00:00" },
Location = new Location() { DisplayName = "Somewhere" },
Body = new ItemBody { Content = "Some Random Text" },
};
Microsoft.Graph.Event addedEvent;
try
{
newEvent.SingleValueExtendedProperties = new EventSingleValueExtendedPropertiesCollectionPage();
newEvent.SingleValueExtendedProperties.Add(new SingleValueLegacyExtendedProperty { Id = "String {00020329-0000-0000-C000-000000000046} Name CompanyID", Value = "12345" });
addedEvent = await graphClient.Me.Calendar.Events.Request().AddAsync(newEvent);
}
catch (Exception e)
{
throw e;
}
return addedEvent;
}
THE SUBSCRIPTION CODE SNIPPET
var subscription = new Subscription
{
ChangeType = "created",
NotificationUrl ="<OUR-URL>",
Resource = "me/events/?$filter=singleValueExtendedProperties/any(ep: ep/id eq 'String {00020329-0000-0000-C000-000000000046} Name CompanyID' and ep/value ne null)",
ExpirationDateTime = DateTimeOffset.Parse("2020-11-13T18:23:45.9356913Z"),
ClientState = "custom_data_state",
LatestSupportedTlsVersion = "v1_2"
};
The subscription is created successfully, but notifications are not being sent for those items containing the specific custom property described above.
It turns out I was only capturing the "created" notification. I neglected to add "updated" and "deleted".
I was testing with an event that already existed in my calendar. No events were being fired because I didn't create the subscription to detect updates and deletes.
Here is the corrected subscription:
var subscription = new Subscription
{
ChangeType = "created,updated,deleted",
NotificationUrl ="<OUR-URL>",
Resource = "me/events/?$filter=singleValueExtendedProperties/any(ep: ep/id eq 'String {00020329-0000-0000-C000-000000000046} Name CompanyID' and ep/value ne null)",
ExpirationDateTime = DateTimeOffset.Parse("2020-11-13T18:23:45.9356913Z"),
ClientState = "custom_data_state",
LatestSupportedTlsVersion = "v1_2"
};
How do you set a new Contact with a yearless birthday with Xamarin iOS?
iOS Documentation states you can just leave the NSDateComponent.year field blank for a yearless birthday.
After trying this in Xamarin iOS, it bugs out the birthday field on the New Contact UI, making it unusable.
var store = new CNContactStore();
var contact = new CNMutableContact();
// construct birthday w/o year
var birthDate = new NSDateComponents();
birthDate.Month = 11;
birthDate.Day = 12;
contact.Birthday = birthDate;
// pop iOS Contact UI
var editor = CNContactViewController.FromNewContact (contact);
editor.ContactStore = store;
editor.AllowsActions = false;
editor.AllowsEditing = true;
navcontroller.PushViewController(editor,true);
You need to save the contact first, then the iOS Contact Editor can handle the year-less date correctly.
var store = new CNContactStore();
var contact = new CNMutableContact()
{
GivenName = "Stack",
FamilyName = "Overflow"
};
var birthDate = new NSDateComponents();
contact.Birthday = new NSDateComponents()
{
Month = 11,
Day = 12,
};
######
var saveRequest = new CNSaveRequest();
saveRequest.AddContact(contact, null);
NSError error;
store.ExecuteSaveRequest(saveRequest, out error);
######
var editor = CNContactViewController.FromNewContact(contact);
editor.ContactStore = store;
editor.AllowsActions = false;
editor.AllowsEditing = true;
PresentViewControllerAsync(editor, true);
Figured it out. You have to set the calendar in the NSDateComponents to Gregorian.
var store = new CNContactStore();
var contact = new CNMutableContact();
// construct birthday w/o year
var birthDate = new NSDateComponents();
birthDate.Calendar = new NSCalendar(NSCalendarType.Gregorian);
birthDate.Month = 11;
birthDate.Day = 12;
contact.Birthday = birthDate;
// pop iOS Contact UI
var editor = CNContactViewController.FromNewContact (contact);
editor.ContactStore = store;
editor.AllowsActions = false;
editor.AllowsEditing = true;
navcontroller.PushViewController(editor,true);
start time 13:00
End time 17:00
get all hours and put to array
output arrHrs = {"13","14","15","16","17"}
You have to try something like that
DateTime startTime = Convert.ToDateTime("01-01-2013 20:00");
DateTime endTime = Convert.ToDateTime("01-02-2013 02:00");
List<DateTime> list = new List<DateTime>();
list = Listhours(startTime, endTime);
Need to create a function like
private List<DateTime> Listhours(DateTime starttm, DateTime endtm)
{
var Listhour = new List<DateTime>();
DateTime startt = Convert.ToDateTime(starttm.ToString("MM/dd/yyyy HH:00:00"));
DateTime endd = Convert.ToDateTime(endtm.ToString("MM/dd/yyyy HH:00:00"));
for (double dblDate = startt.ToOADate();
dblDate <= endd.ToOADate();
dblDate += (1.0 / 24.0))
{
Listhour.Add(DateTime.FromOADate(dblDate));
}
return Listhour;
}
Hope it works.
var startTime = 13, endTime = 17;
var arrHrs = new List<int>();
while(startTime <= endTime)
{
arrHrs.Add(startTime++);
}
OR in an easier way
var startTime = 13, endTime = 17;
var arrHrs = Enumerable.Range(startTime, endTime);
I need to get the master appointment of the meeting series, when an appointment instance is opened.
I have tried the following (currentAppointment variable is of type AppointmentItem)
DateTime sd = currentAppointment.GetRecurrencePattern().PatternStartDate;
DateTime st = currentAppointment.GetRecurrencePattern().StartTime;
AppointmentItem ai = currentAppointment.GetRecurrencePattern().GetOccurrence(sd+st.TimeOfDay);
However, while this gets me the first appointment in the series, it has a RecurrenceState of olApptOccurrence.
How can I get a reference to the olApptMaster - ie the meeting series?
AppointmentItem.Parent will return the parent AppointmentItem for the recurrence instances and exceptions.
I have a method to create an appointment item with recurrence, but it´s almost the same as modifying one, tell me if that helps you and if you need further information.
Here is the code in C#
private void CreateNewRecurringAppointment(Outlook._Application OutlookApp)
{
Outlook.AppointmentItem appItem = null;
Outlook.RecurrencePattern pattern = null;
try
{
appItem = OutlookApp.CreateItem(Outlook.OlItemType.olAppointmentItem)
as Outlook.AppointmentItem;
// create a recurrence
pattern = appItem.GetRecurrencePattern();
pattern.RecurrenceType = Outlook.OlRecurrenceType.olRecursWeekly;
pattern.StartTime = DateTime.Parse("9:00:00 AM");
pattern.EndTime = DateTime.Parse("10:00:00 AM");
// we can specify the duration instead of using the EndTime property
// pattern.Duration = 60;
pattern.PatternStartDate = DateTime.Parse("11/11/2011");
pattern.PatternEndDate = DateTime.Parse("12/25/2011");
appItem.Subject = "Meeting with the Boss";
appItem.Save();
appItem.Display(true);
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
finally
{
if (pattern != null)
System.Runtime.InteropServices.Marshal.ReleaseComObject(pattern);
if (appItem != null)
System.Runtime.InteropServices.Marshal.ReleaseComObject(appItem);
}
}
source: http://www.add-in-express.com/creating-addins-blog/2011/11/07/outlook-recurring-appointment/