How can I attach a javascript snippet to run when an event is dragged from one date to another on the calendar?

  • 1
  • Question
  • Updated 3 years ago
  • Answered
We wrote code to update future bookings on a calendar, we want it to run when an event is dragged to a new date. Any ideas?
Photo of Anna Orias

Anna Orias

  • 1,468 Points 1k badge 2x thumb

Posted 3 years ago

  • 1
Photo of Zach McElrath

Zach McElrath, Employee

  • 48,984 Points 20k badge 2x thumb
You could run the Snippet as a result of a Model Action on the Model(s) corresponding to your Calendar Event Sources.

For instance, if you have a Model on the Salesforce Event object that is used as a Calendar Event Source, then you could add a Model Action to the event Model on the "Row in Model updated" Initiating Event, on the StartDateTime/EndDateTime fields. Add a Snippet as the one Action that gets run. This will be run whenever the StartDateTime or EndDateTime fields are changed on your model. You could do something similar for each of the other Event Source Models on your calendar, you could have a Model Action defined for each Model, all on the "Row in Model updated" Initiating Event, that runs the same JavaScript Snippet.
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Wow.  Just wow... Thanks Zach. 
Photo of Anna Orias

Anna Orias

  • 1,468 Points 1k badge 2x thumb
Zach, Thanks. We started with that solution and our issue was that if someone tries to edit it in list view, the action starts to run right when we select a field to edit it, that is before we type in the edits that need to run. We also tried to change it to trigger when the model is saved. Finally, we found that we needed two duplicate models to run the snippet, one to loop over, and one to view on the calendar. This further complicates the action. We came up with the idea of a row action, yet that gets a bit clunky. Any ideas for how to fire the edits when the editing is finished, rather than when it starts?