Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
Graph JS
>
Tutorial
> Update appointment - Reschedule for tomorrow
Update Start and End time to move the appointment for tomorrow.
import { GraphClient } from '../independentsoft/graph/graph.js'; import { UserId } from '../independentsoft/graph/users.js'; import { Event, EventPropertyName, DateTimeTimeZone } from '../independentsoft/graph/calendars.js'; import { Query, And, IsGreaterThanOrEqualTo, IsLessThanOrEqualTo } from '../independentsoft/graph/query-options.js'; async function mainFunc() { try { const client = new GraphClient(); client.clientId = "xxxxxxxxxx-209e-454e-xxxxxxxxxxxxxxxxxxx"; client.tenant = "independentsoft.onmicrosoft.com"; client.clientSecret = "xxxxxxxxx.ONVE[=zYYxxxxxxxxxxxxxxxx"; const now = new Date(); const startTime1 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0); //today at 10 AM const startTime2 = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 0, 0); //today at 12 PM const condition1 = new IsGreaterThanOrEqualTo(EventPropertyName.START_TIME, startTime1); const condition2 = new IsLessThanOrEqualTo(EventPropertyName.START_TIME, startTime2); let query = new Query(); query.top = 100; query.filter = new And(condition1, condition2); const appointments = await client.getEvents(undefined, undefined, new UserId("info@independentsoft.onmicrosoft.com"), query); for(let i=0; i < appointments.length; i++) { const oldStartTime = appointments[i].start.time; const oldEndTime = appointments[i].end.time; const newStartTime = new Date(oldStartTime.getFullYear(), oldStartTime.getMonth(), oldStartTime.getDate(), oldStartTime.getHours() + 6, 0, 0); const newEndTime = new Date(oldEndTime.getFullYear(), oldEndTime.getMonth(), oldEndTime.getDate(), oldEndTime.getHours() + 6, 0, 0); let tempAppointment = new Event(); tempAppointment.id = appointments[i].id; //important tempAppointment.start = new DateTimeTimeZone(newStartTime); tempAppointment.end = new DateTimeTimeZone(newEndTime); const updatedAppointment = await client.updateEvent(tempAppointment, undefined, new UserId("info@independentsoft.onmicrosoft.com")); } } catch (e) { console.error(e.code) //error code console.error(e.message) //description console.error(e.date) //timestamp console.error(e.innerError) //innerError } } mainFunc();
Need help? Ask our developers:
Name*
Email*
Message*