Help me write a script please

Would be grateful if someone helps me to write a script to

  • Find all events going back 7 days, in a specified calendar, say “Test”
  • And change and update begin and end dates to today’s date
    Thanks in advance.

I don’t believe you will be able to change the dates on the events. I think you would need to create new ones and remove old ones.

Algorithmically I think you want something like this.

  1. Retrieve calendar events in the next 7 days - see this for the basis of how to do that.
  2. For each event you retrieve:
    1. Create a new event but with the revised dates.
    2. If created successfully remove the event.

Does that make sense?

Absolutely. And I can see how the events can be retrieved (from the example) however I havent a clue how to delete and create new events in a loop.

Thanks for your help.

Not sure about deleting or if updating an existing calendar event is actually possible, but did you read on from the calendar documentation to the event documentation page?

That has more examples…

Thanks anyway. :pray::pray::pray::pray:

You can update existing events, as long as you have write access to them on the Calendar. If you have retrieved them from a Calendar, you can change values and call update() on the event to save changes, something like:

let start =;
let end =;
let cal = Calendar.find("Test");
let events =, end);

for (let event of events) {
    event.startDate = // PUT NEW DATE VALUE!

This works beautifully. Thanks a lot !