Custom Event Actions

Event actions let you add your own actions everyday calendar operations instead of buttons You can attach your own actions to clicking, saving, or deleting an event. Actions that can be performed are opening a URL or running JavaScript code, just as you can with button actions. Unlike custom button actions, where users initiate the action by clicking a button, event actions are initiated by actions users are already taking 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: "instead of <doing 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.
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 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 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

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  


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


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

Still need help? Message Us Message Us