Custom Event Actions
Event actions let you add your own actions to everyday behaviors in the calendar. You can attach actions to clicking, saving, or deleting an event. As with button actions, actions can be performed by opening a URL or running JavaScript code. Unlike custom button actions--where users initiate the action by clicking a button--event actions are initiated by things users are already doing in the calendar: clicking on an item, saving an item, or deleting an item.
Uses for event actions
Event actions are used to change the way DayBack behaves. You might use one to prevent deletion of events in certain cases or to jump right to your own Salesforce page instead of editing an item in DayBack's popover.
Think of event actions as "hijacking" DayBack's native behavior: in addition to <whatever DayBack does when you save an event> I want to do <this>.
Creating an event action
Creating a new action is pretty easy:
-
1
-
Log in to
admin settings and select the source you're interested in.
-
2
-
Scroll down past the Source Settings and Field Mapping until you see "Event Actions"
-
3
-
Click "Add New Event Action" and pick the event that should trigger the action.
-
4
-
Paste the code you'd like to execute where it says "URL or JavaScript". This is obviously the tricky part--writing the action itself. Don't hesitate to
get in touch and ask for help. (Note that you can also drag JS files into the code editor in DayBack if you'd rather compose your JavaScript functions in your own editor.)
-
5
-
That's it.
Events that can trigger actions
On Event Create
- Actions here happen right when a new event is created on the calendar.
- This happens right before the popover is rendered, so you can modify the editEvent object to set field values as desired.
- "Prevent default action" would stop DayBack from creating a new event and rendering the event popover.
- See objects available in this context here.
On Event Click
- Actions set to this trigger will fire whenever a user clicks on an event in DayBack.
- They'll also fire as soon as a new event is created, so you can also think of this trigger as "on popover render"
- "Prevent default action" in this case prevents the popover from rendering.
- See objects available in this context here.
On Event Hover
On Field Change
Before Event Rendered
- Actions set to this trigger will fire after DayBack has retrieved the events but before drawing each to the calendar. This action runs once per event about to be painted. This is the action you'd use if you want to transform the way an event is displayed on the calendar or even prevent it from displaying.
- "Prevent default action" would stop DayBack from rendering an event unless the action fires the confirming action, "action.callbacks.confirm();".
- See objects available in this context here.
Before Event Save
- Actions here would happen before changes to an event are processed.
- This happens when users click "Save..." in the item's popover, or when they complete a drag operation in the calendar.
- This is the best trigger for when you need to mutate the event before it is saved.
- "Prevent default action" would stop DayBack from continuing to save the action, but you could end your event action with code to execute the save yourself. This is how the example below for preventing dragging from changing an event's time works.
- See objects available in this context here.
On Event Save
- The action is triggered after DayBack processes the changes but just before the changes are written to the data store.
- This happens after the Before Event Save trigger, after the event changes have been processed.
- "Prevent default action" would stop DayBack from writing the changes back to the data store, but you could end your event action with code to execute the save yourself.
- This is useful for writing changes to an alternate place (cloning data to another data store), or mutating the data before it is sent to the data store. For example, if you want to prevent DayBack from trying to write back to a formula/calculated field.
- DayBack lets users undo their changes; your action can test for the undo property and behave differently when edits are reverted.
- See objects available in this context here.
On Event Delete
- The only way this action gets triggered is from the "Delete" button inside DayBack's popover.
- Like On Event Save, "Prevent default action" here would stop DayBack from writing the delete back to the data store (Google or Salesforce, for example).
- See objects available in this context here.
Note that "On Event Save" and "On Event Delete" actions can affect the "Saved" and "Deleted" notifications that pop up from the bottom of the screen to confirm an event. If you select "Prevent default action" to be "yes", DayBack will not show the success notification after your action because DayBack wouldn't know if your action saved or deleted the event after all. You can, however, call the notification in your own code. =)
Examples
Here are some example actions to get you thinking about how you can customize your calendar. Please copy and paste these into your DayBack, and don't hesitate to reach out if you get stuck.
Remember that you have access to fields from your Salesforce item when your action executes. These fields are represented by "data tokens" where the fields you've mapped to your event can be wrapped in [[double brackets]] when used in your actions. You also have access to the state of your item before a user began editing it =) Learn more about data tokens, event attributes, and the functions available to your event actions here: APIs: Resources for Custom and Event Actions.
Prevent Resource Conflicts in Salesforce
Use |
This Custom Event Action will prevent an event from being double-booked if there's an existing event with the same resource and overlapping times in the same Salesforce object. This is a DayBack only version of the examples we published here: Date Range Conflicts in Salesforce. Those examples work in the backend and prevent conflicts when events are edited in DayBack or in other Salesforce screens. This action only fires when events are edited in DayBack, but it's much simpler and easier to customize. There is also a FileMaker version of this action you can paste into DayBack. |
Trigger |
Before Event Save |
Script |
The code, a demonstration video, and details are available here: Prevent Resource Conflicts in Salesforce. |
Options |
Open in new window: No Prevent default action: Yes |
Force single selection for statuses and/or resources
Use |
This will force resource and status selection to be a single value only. This is particularly useful on mobile where multi-select is the normal behavior but the field only supports a single value. |
Trigger |
On Field Change |
Script |
ForceSingleSelect.zip |
Options |
Open in new window: No Prevent default action: Yes |
Specify resources shown for each calendar with tags
Use |
This allows you to specify the list of resources to show in the popover for each calendar by adding some tags to the resource. This action checks the tags of resources and folders. So you can include or exclude an entire folder of resources to show for a specific calendar. Here's a video of how this works and the tags you'll use to configure it. |
Trigger |
On Event Click |
Script |
ResourceListToggle.zip |
Options |
Open in new window: No Prevent default action: No |
Prevent popovers from displaying
Use |
You'd like your users to be able to see items from a particular source and drag them around, but they don't need to see or change any other details. This mod effectively turns off DayBack's click-on-event action for this source. |
Trigger |
On Event Click |
Script |
var dummy; |
Options |
Open in new window: No Prevent default action: Yes
Note that you can use this var dummy; to turn off any of the trigger actions, including turning off deletes.
|
Go right to the item on click
Use |
Rather than bring up the DayBack Calendar popover when users click on an item, you'd like them to jump right to the item's page in Salesforce. This is effectively using the "Go To Event" custom action example as an event action. |
Trigger |
On Event Click |
Script |
fbk.publish ( "dbk.navigate" , { "url" : "/[[Id]]" , "new" : false } )
|
Options |
Open in new window: No Prevent default action: Yes |
Change the event's status if a checkbox is checked.
Use |
Users are marking an additional field named "meeting attended" when the contact on an event shows up. If they forget to mark the event closed, this action will change the status to closed when the event is saved. This action also shows how to reference additional fields by your application's Store In Filed Name instead of their DayBack numerical ID for Calendar Actions: Example:
// Standard way of referring to Custom Fields by numerical ID:
editEvent['1234996543210-4152637485'] = meetingAttendedFlag;
// Example function call that looks up the numerical ID by your
// application's Store in Field name:
editEvent[getFieldIdByName('meetingAttendedFlag')] = meetingAttendedFlag;
|
Trigger |
Before Event Save |
Script |
SetStatusOnCheckboxChecked.js |
Options |
Open in new window: No Prevent default action: No |
Prevent dragging from changing an event's time
Use |
Your users are primarily using the schedule views to assign items to resources and you don't want them changing an item's time when they do so. This mod will snap an event back to its original time if dragging the event accidentally includes a change to the event time. |
Trigger |
Before Event Save |
Script |
//Before Event Save
function noTimeChange() {
//drag and drop or popover edit?
if(event.beforeDrop) {
if(event.allDay!==event.beforeDrop.allDay || !event.start.isSame(event.beforeDrop.start) || !event.end.isSame(event.beforeDrop.end)) {
event.allDay = event.beforeDrop.allDay;
event.start = event.beforeDrop.start.clone();
event.end = event.beforeDrop.end.clone();
}
}
}
noTimeChange();
|
Options |
Open in new window: No Prevent default action: No |
Add a default duration to an event
Use |
DayBack has a setting for an app-wide default duration, but if you'd like to change the duration for specific calendars, this action is a great way to go since event actions are scoped to specific calendars. (See also: Default Values for Each Resource) |
Trigger |
On Event Create |
Script |
// Set default duraton
Initialize(editEvent, seedcodeCalendar);
function Initialize(editEvent, seedcodeCalendar) {
editEvent.end = moment(editEvent.start).add(30, 'm'); // Default duration is 30 min
}
|
Options |
Open in new window: No Prevent default action: No |
Prevent dragging from changing an event
Use |
You'd like to prevent accidental drag+drop changes from modifying an event in a particular source. This will prevent any dragged events from saving the changes to the event. |
Trigger |
On Event Save |
Script |
//Revert changes if the event was dragged and dropped
if (event.beforeDrop) {
action.callbacks.cancel();
}
else{
action.callbacks.confirm();
}
|
Options |
Open in new window: No Prevent default action: Yes |
Retrieve custom parameter from URL
Use |
You'd like to pass custom parameters in the URL for use within the calendar. This can be useful when loading DayBack in a FileMaker WebViewer and you'd like to pass parameters for use when creating or editing events. In this scenario, we're retrieving the parameter "sessionID" from the URL string and assigning it to an additional field in the event. This takes effect when an existing event is clicked on or a new event is created. |
Trigger |
On Event Click |
Script |
//Gets the sessionID parameter from the URL and populates the additional field
function getSessionID() {
'use strict';
var sessionID = getUrlVars().sessionID;
editEvent['1234996543210-4152637485'] = sessionID;
}
//Function to retrieve parameters from the URL
function getUrlVars() {
'use strict';
var vars = {};
var parts = location.href.substring(0, location.href.indexOf('#/')).replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}
getSessionID();
|
Options |
Open in new window: No Prevent default action: No
|
Make past events read-only
Use |
You'd like to have events that start in the past be read-only, but events in the future need to be editable. This is actually two actions that should be used together. The on-click action dynamically makes the pop-over read-only and the before-save action prevents past events from being dragged and dropped. |
Trigger |
On Event Click |
Script |
ReadOnlyPastOnClick.js |
Options |
Open in new window: No Prevent default action: No |
Trigger |
Before Event Save |
Script |
ReadOnlyPastBeforeSave.js |
Options |
Open in new window: No Prevent default action: Yes |
Send an email when an event is set to a specified status
Use |
You'd like to notify someone when an event's status (or another field) is set to a specified status ('On Hold' in this example). This will automatically compose an email with a notification that the event is in the specified status and containing the title, description, and a link to the event. |
Trigger |
On Event Save |
Script |
emailSupportOnHold.js |
Options |
Open in new window: No Prevent default action: No |
Use |
This custom event action will automatically assign a parent customer record ID to all newly-created events. This Salesforce customization is one possible way to allow individuals to see each other’s Events and Tasks. |
Trigger |
On Event Create |
Script |
SetEventParentContact.zip |
Options |
Open in new window: No Prevent default action: Yes |
Use |
You'd like to update the location field for a Salesforce Event object based on the related contact and see the update in the open popover without having to save the event first. |
Trigger |
On Field Change |
Script |
LoadContactAddress.js |
Options |
Open in new window: No Prevent default action: Yes |
Disable All-Day Events
Use |
You'd like to prevent All-Day events from being created on the calendar and convert them to scheduled events automatically. This On Event Create action converts all-day events into a scheduled event at the current time-slot with the duration set from your DayBack settings. |
Trigger |
On Event Create |
Script |
disableAllDayEventsV1.js |
Options |
Open in new window: No Prevent default action: No |
Assign the Logged In User as a New Event's Resource
Use |
When a new event is created, you'd like the current user to be assigned as the event's resource. Note that resources are arrays (like statuses) so the value assigned to a resource must be in brackets, like ['some string'] or, as in this example, [seedcodeCalendar.get('config').accountName] |
Trigger |
On Event Create |
Script |
//Add's the creator as a resource to new events
Initialize(editEvent, seedcodeCalendar);
function Initialize(editEvent, seedcodeCalendar) {
editEvent.resource = [seedcodeCalendar.get('config').accountName];
}
|
Options |
Open in new window: No Prevent default action: No |
Cascading Changes Through Linked Events
Use |
Link events on your calendar so that scheduling changes cascade through all the downstream activities in your project. |
Trigger |
On Event Save |
Script |
This action has a number of configuration options described in our blog post on cascading events. You can download the action itself here: cascadingEvents.js |
Options |
Open in new window: No Prevent default action: Yes |
Confirm Appointments or Collect Information in a Form
Use |
Designed to be run as an event action in a shared view, this will show a simple wufoo form when a recipient clicks on an event. DayBack passes some event details into the form and then a receipt of the confirmation is sent to the recipient and the organizer. We use a wufoo form in this example since it's simple: field validation and emailing are all handled by wufoo so the event action we have to write is pretty simple. Here's a short video of this one in action. |
Trigger |
On Click |
Script |
confirmAppointmentWuFooForm.js |
Options |
Open in new window: No Prevent default action: Yes |
Validate Data Entry
Use |
This custom function allows you to specify fields in which you would like to verify data entry. If a specified field is left empty, a notice will pop-up notifying the user and allowing them to continue editing the event in the popover, or save the event with the empty fields. Click here for a video of it in action. |
Trigger |
Before Event Save |
Script |
ValidateFieldEntry.js |
Options |
Open in new window: No Prevent default action: Yes |
Check Resource Capacity
Use |
This Before Event Save event action prevents an event from being saved if it will result in the specified resource going over its daily limit of events. This daily limit is specified in a configuration object at the top of the JS code. If the resource will become over its limit, an error message will show which days would be over capacity and the edit is canceled. |
Trigger |
Before Event Save |
Script |
checkResourceCapacityV1.js |
Options |
Open in new window: No Prevent default action: Yes |
Warning when Creating in the Past
Use |
This On Event Create event action generates a modal dialog if the new event starts in the past. The user can then choose to cancel or continue. |
Trigger |
On Event Create |
Script |
InThPastWarningV1.js |
Options |
Open in new window: No Prevent default action: Yes |
Looking up a Resource ID by Name (Salesforce)
Use |
Allows you to use a related field as the resource by looking up the id from the resource name and editing the relationship. |
Trigger |
On Event Save |
Script |
LookUpResourceId.js |
Options |
Open in new window: No Prevent default action: Yes |
Override Start Field when editing (Salesforce)
Use |
This Salesforce On Event Save event action allows you to specify an alternate Start field to edit instead of the one specified in field mapping. This is useful for when you've mapped you Start field to a formula field to, for example, just have the current user see their own events. Here's an example of such a formula field: if ( $User.Id = OwnerId , If( IsAllDayEvent , DATETIMEVALUE(ActivityDate) , ActivityDateTime ) , DATETIMEVALUE('') )
|
Trigger |
On Event Save |
Script |
OverrideStartEdit.js |
Options |
Open in new window: No Prevent default action: No |
Merge information to/from Google Calendar (Salesforce)
Use |
You can also use custom actions to script interactions between Salesforce and Google Calendar. You'll find code for a couple of examples here: looking up Salesforce data into Google Calendar events, and creating a new Salesforce record from a Google Calendar event. |
Trigger |
Multiple |
Script |
Two examples here: Google Calendar Actions in Salesforce |
Options |
Open in new window: Multiple Prevent default action: Multiple |
Push events to Google Calendar
Use |
DayBack can push events from other calendars to Google, so these events block out your availability in Calendly. This isn't "syncing" with Google, as changes made in Google aren't brought back into your other calendars, but it's a great way to build a Google Calendar out of specific events from Salesforce or FileMaker caledars... or even from select events in other Google calendars. |
Trigger |
Multiple |
Script |
Find a description and download code for the two required actions here: DayBack and Calendly |
Options |
Open in new window: No Prevent default action: Yes |
Change Behaviors when Special Keys are pressed
Use |
This pair of actions teaches DayBack to listen for the keys you're holding down and then let you test for these in your custom actions. A common use case for this would be to change what happens when you click on an event if the "z" key is held down. (Note that DayBack is already listening for the shift and option keys, and the command key is reserved by the browser, so using "regular" keys is recommended here.) |
Trigger |
One BeforeCalendarRandered app action, and one OnEventClick event action. |
Script |
The two actions are available here: ListenForKeyDown.zip |
Options |
Open in new window: No Prevent default action: Probably |
Remove Attendees from Events when Duplicating (Google Calendar)
Use |
When you drag-duplicate an event containing attendees, you likely don't want the attendees copied to the new event. Or at least you'll want to reset their "accepted" status. This action removes the attendee object entirely; you could go further and edit just event acceptance by examining the properties of the event.attendees object. If you're going to change the event's calendar after dragging, apply this action to the origin calendar, not the destination calendar: the On Event Create is fired as soon as the event is rendered on-screen (which happens right after it's duped and is still in the original calendar). |
Trigger |
On Event Create |
Script |
event.attendees = [];
|
Options |
Open in new window: No Prevent default action: No |
Default Values for each Resource
Use |
Set a default duration--or any value--for each of your resources. While you can usually set defaults in the backend, using a trigger or a formula field, those don’t evaluate until the appointment is committed to the back end. Using an action like this adds the defaults to the event as soon as users begin creating it. |
Trigger |
On Event Create |
Script |
See a video of this in action and copy the code you'll want for your own version here: Default Durations for each Resource |
Options |
Open in new window: No Prevent default action: Yes |
Use |
If a field in your event lists the skills ( tags) required, this action will bark if the resource(s) you select for the event doesn't contain all the required tags. Required tags are specified as a comma-separated list in the event, and you'll specify which field contains the required list in the action's configuration. |
Trigger |
Before Event Save |
Script |
You can see this action at work towards the end of the video introducing resource tags. You'll find the code for his action here: event-requires-tags.js |
Options |
Open in new window: No Prevent default action: Yes |