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 are 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.

In this article


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 when the popover is rendered, so you can modify the editEvent object to set field values as desired.
  • "Prevent default action" would stop DayBack from writing the changes back to Salesforce, but you could end your event action with code to execute the save yourself. This is how the "prevent editing times" example below works.
On Event Click
  • Actions set to this trigger will fire whenever a user clicks on an item 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. 
On Event Hover
  • Actions will fire whenever a user hovers over an event: most often used for tooltips
  • There is no default hover behavior, so "Prevent default action" does nothing.
On Field Change
  • Actions here will fire when a value is selected for a field in the popover
  • Currently, supported fields are Calendar, Status, Resource, Contact, and Project
  •  "Prevent default action" will prevent the field from being updated in the popover unless action.callbacks.confirm() is called
  • Fields can be updated within the popover using this action. See the "load contact address" example below.
Before Event Save
  • Actions here would happen before changes to an event are written back to Salesforce.
  • This happens when users click "Save..." in the item's popover, or when they complete a drag operation in the calendar.
  • "Prevent default action" would stop DayBack from writing the changes back to Salesforce, but you could end your event action with code to execute the save yourself. This is how the "prevent editing times" example below works.
On Event Save
  • Actions here would happen when changes to an event are written back to Salesforce.
  • This happens when users click "Save..." in the item's popover, or when they complete a drag operation in the calendar.
  • "Prevent default action" would stop DayBack from writing the changes back to Salesforce, but you could end your event action with code to execute the save yourself. This is how the "prevent editing times" example below works.
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).

Note that "On Event Save" and "On Event Delete" actions can affect the "Saved" and "Deleted" notification that popup 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 a couple of example actions to get you thinking about what these can be used for as with custom actions. 

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 scheduled if there's an existing event with the same resource with 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.
Trigger   Before Event Save
Script PreventConflictByResource.js
Options Open in new window: No  Prevent default action: Yes


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 their ID, instead of their name.
Trigger   Before Event Save
Script
// Mark item status as closed if 'meetingAttended' field is changed and set to true
// meetingAttended is a custom field with the ID 1524201086983-6909833999

function meetingAttendedStatus() {
      if(editEvent['1524201086983-6909833999']===true && (editEvent['1524201086983-6909833999']!==event['1524201086983-6909833999'])) {
        editEvent.status = ['Closed'];
      }
}
meetingAttendedStatus();)
		
Options Open in new window: No  Prevent default action: No


Prevent dragging from changing an item's time

Use Your users are primarily using the schedule views to assign items to resources and you don't want them changing an items 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 a 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.
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

Note: A few example DayBack URLs that could be used in with this custom action:

https://app.dayback.com/?SessionID=123

https://app.dayback.com/?SessionID=123#/?filterProjects=MyProject

https://app.dayback.com/?userToken=[YourUserToken]&SessionID=123  


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


Load Contact Address To Event Location

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 FieldChange
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 ChangesThrough 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 is 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


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

Still need help? Message Us Message Us