Calendar Events that Trigger Tasks with Different Dates

My workflow has a Google Calendar event that triggers steps which create other Google Calendar events and Google Tasks entries. Those entries need to be on different dates or times than the original calendar event, some before and some after. I can add the {{steps.trigger.event.start.dateTime}} from the calendar event trigger to the event or task due date, but because I’m not well versed in code, I don’t know how to add an instruction onto the due date that will cause it to be before or after the original event date. I would appreciate some help with this!

Hi @timschwindt,

To modify the date and time of the original Google Calendar event, you can use JavaScript’s Date object to add or subtract time from the original event date. Here’s an example of how to add or subtract time from the steps.trigger.event.start.dateTime:

export default defineComponent({
  async run({ steps }) {
    const originalDate = new Date(steps.trigger.event.start.dateTime);

    // Add or subtract time (in milliseconds)
    const hoursToAdd = 2;
    const newDate = new Date(originalDate.getTime() + hoursToAdd * 60 * 60 * 1000);

    // Now you can use newDate in your Google Calendar or Google Tasks steps
    // For example: newDate.toISOString()
  },
});

In this example, I added 2 hours to the original event date. You can modify the hoursToAdd variable to add or subtract any number of hours. Remember to use a negative value to subtract hours.

Now you can use the newDate.toISOString() in your Google Calendar or Google Tasks steps to set the new date and time.
I’m a bot powered by Pipedream and GPT-4. I’m still learning, so please double check my answers and code! Learn how to build your own.

Where in my workflow do I insert the code? And where do I use the newDate.toISOString()? Sorry I don’t know enough about code.

I have added this code between my trigger and my actions which consist of one calendar event and multiple task entries. My actions need to have different start dates or times, relative to the original calendar event that triggers them. How do I configure the code so that adding a simple instruction to the “Due” field in each action will cause the it to be created on the correct date for that action? And how exactly do I use the “newDate” in each step to set the new date or time?

Hi @timschwindt,

Could you share screenshots of your entire workflow? I would like to understand your workflow current state.

Also could you give an example of your usecase? For example, I have a task A triggered at 10:00AM, I would like to create a task due at 10:30AM

Hi @vunguyenhung.

I am a wedding officiant, and every time I create a wedding ceremony in my calendar, there are 11 different actions consisting of calendar events and tasks that need to be created, so that I will remember to do everything necessary for that wedding ceremony, both leading up to it and afterward. I need to automate this process as I officiate many weddings per year. Here is exactly what my workflow needs to do:

  • I create an event in my Google Calendar with a specific title [EP Wedding Ceremony] and description [Name of the couple], in a specific calendar [Enduring Promises] in my Google account. That event serves as the trigger for all of the subsequent actions.

  • The first action is another calendar event which is to start 30 minutes after the original event, in a different calendar in the same Google account, with an end time the same as the original event. It also needs a notification at its start time (I haven’t figured out how to do that).

  • The next 10 actions are Google Task entries on various dates relative to the date of the original calendar event. The first one needs to be 60 days before the original event, the second one 12 days before, the third one 5 days before, the fourth one 3 days before, the fifth and sixth ones 2 days before, the seventh and eighth ones on the same day as the original event, the ninth one 2 days after, and the tenth one 14 days after. None of these tasks need specific times assigned to them, only dates, and none of them need notifications.

Here are screenshots of my workflow. You will see that currently there are no additional instructions after the {{steps.trigger.event.start.dateTime}} in the Event Date field of the calendar action, or in the Due field of each task action, as I’m not entirely sure how to properly use the code given to me by your support team. Thank you in advance for your help!

Tim

Screenshot 2

Screenshot 3

Screenshot 4

Screenshot 5

Screenshot 6

Screenshot 7

Screenshot 8

Screenshot 9

Screenshot 10

Hi @timschwindt,

In stead of using code, you can use the Pipedream Formatting action > Add Subtract Time to add minutes or hours to your original date

Please select the output format that is accepted by the Google Calendar - Create Event action

Hi @vunguyenhung.

I don’t understand how this action will change the date or time of my subsequent actions. I created this action between my trigger and my next action, specifying 30m as the shorthand Duration in order to add 30 minutes to the original date. But when I run the next action (which is supposed to create a calendar event 30 minutes later than the original event), it creates an event at the SAME time as the original event, because the Event Date is specified as {{steps.trigger.event.start.dateTime}} in that action. And if I add another command from my new “Add_30m” action to the Event Date after the {{steps.trigger.event.start.dateTime}} command, it returns a Bad Command error. So how can the Add Subtract Time action cause the next action to be earlier or later than the original event date or time? Is there not a shorthand command that can be added to the {{steps.trigger.event.start.dateTime}} command in the Event Date field of each action itself, in order to cause its start time to be before or after the trigger event? For example, I previously used Zapier, and I was able to add +30m or -60d as text at the end of a start date & time command which told the action to start 30 minutes after or 60 days before the original event. Thanks for your help! Tim

Hi again. Just a nudge regarding my last reply, I’m still not knowing how to actually implement the solution you proposed. I would appreciate your help. Thank you! Tim