APIs and JavaScript in DayBack
DayBack provides both inbound and outbound APIs to enhance its functionality and integrate with other applications. DayBack can be customized using JavaScript code, and most of our popular extensions and integration examples available in our open source extensions library.
Inbound APIs:
Inbound APIs allow you to create buttons on your Salesforce pages or FileMaker layouts that control DayBack's behavior. These buttons can manipulate DayBack's URL to perform actions such as navigating to a specific event or view, or filtering for a particular campaign. Learn more about adding DayBack buttons to your layouts.
Outbound APIs:
Outbound APIs, also known as webhooks, enable you to run your own scripts from within DayBack or call routines in other applications. Most outbound calls are triggered by button actions, which are available within an event's popover.
Ways to Add Custom Code to DayBack
If you're not already familiar with various customizations you can add to DayBack, here's a brief overview of the three major types:
- Custom Button Actions:
- Custom button actions are available from DayBack's event popover and can be used to perform event-specific tasks, such as starting a Zoom meeting, sending an email, or navigating to the event's native record in Salesforce or FileMaker.
- Custom Event Actions:
- Custom event actions are triggered by event-related changes occurring within the calendar, such as editing, creating, or deleting events. These actions trigger automatically when the user performs an action related to the creation, scheduling, or modification of an event record.
- Custom App Actions:
- Custom app actions affect DayBack's loading behavior, influencing the retrieval and display of data, filters, and resources, and when the user navigates between different views.
The remainder of this article describes the JavaScript libraries and data tokens available for use within all action types.
In this article
Using JavaScript In Custom Actions
You can use almost any JavaScript in your custom actions within DayBack. However, you won't have access to the global window
object directly. You can still call built-in functions like open()
, close()
, alert()
, and location.href
, but without prefixing them with window.
. For instance, use location.href
instead of window.location.href
.
Working with Salesforce Data
For Salesforce integrations, you can use the Canvas JavaScript SDK, a powerful library that includes its own ajax
function for making REST calls to Salesforce directly from DayBack. DayBack provides two functions to help you retrieve the Client and Context objects needed for these calls:
fbk.client()
: Used for authenticating yourajax
calls.fbk.context()
: Contains metadata about the current user, their organization, and current URLs for making REST calls.
Refer to the Canvas JavaScript SDK Function Reference for detailed usage and examples.
For practical examples of using fbk.client()
and fbk.context()
in DayBack custom actions, see the "Create a New Salesforce Record from a Google Calendar Event" example in Google Calendar Actions in Salesforce.
Launching Your Code
You don't need to use onload
or jQuery $.ready()
functions to initiate your code, as all code executes automatically based on the following events:
- Button actions execute when a button is clicked by a user.
- Event actions execute when the user interacts with an event.
- App actions execute during DayBacks loading sequence or when navigation changes are initiated by a user.
Included Libraries
DayBack includes popular libraries like jQuery, Bootstrap, and moment.js, which you can use in your custom actions, along side DayBack's extensive Objects and Methods.
Using data tokens in Salesforce and FileMaker
DayBack allows you to specify data tokens, which are replaced by event data when a custom action is run. This is useful for passing event data to other services.
- Data tokens are wrapped in double brackets with the mapped field name, e.g.,
[[DataToken]]
. - Tokens use the names assigned during field mapping in the source settings.
Example URL:
http://www.somewebsite.com?id=[[Id]]&date=[[StartDateTime]]
When using data tokens in JavaScript, wrap the token in quotes to avoid errors if the value is empty. This ensures all data tokens are treated as strings:
var eventID = "[[Id]]"; alert(eventID);
For boolean values like allDay
, use a string comparison:
var isAllDay = "[[IsAllDayEvent]]" === "true"; // Evaluates to a boolean
Using Data Tokens with Google Calendar
Since no field mapping is necessary for Google Calendars, you'll use DayBack's own name for each data object when writing custom actions for your Google events. Here are the names of each of the properties you can reference in a custom action for a Google Calendar event:
eventID
allDay
start
end
title
titleEdit
description
resource
status
location
contactID
contactName
projectID
projectName
By following these guidelines, you can effectively use JavaScript and data tokens to extend the functionality of DayBack and integrate it seamlessly with other applications.
Using Custom Fields in Your Custom Actions
When using JavaScript to access your custom fields inside Event Actions and Button Actions, you need to reference the custom field's DayBack ID. This ID is shown in the Additional Fields tab as the "ID for Calendar Actions" inside the event object.
For example, in the screenshot below, you'll see the ID for the field named truckNumber
looks like 1721951289977-5615655122
.
To edit an event's truckNumber
field, use this ID as the name of the property in either the event
or editEvent
object. You can read more about other values available in your event object here.
// Set truckNumber using the field's ID event['1721951289977-5615655122'] = "Truck Number 1";
To check metadata about additional fields (such as their format), you can reference the object like this:
event.customFields['1721951289977-5615655122']
To make your app action code more readable, it's often preferable to refer to your numerical Field IDs by a human-readable name inside your JavaScript. Here's an example that retrieves the numerical ID, using the Custom Field name 'truckNumber' defined inside the current event's schedule
object. This code uses the dbk.getCustomFieldIdByName()
helper function to introspect this object.
// Retrieve numerical ID for truckNumber const customFieldId = dbk.getCustomFieldIdByName('truckNumber', event.schedule); const truckNumber = event[customFieldId]; // Set truckNumber using the field's ID event[truckNumber] = "Truck Number 1";
Learning Resources
Available Objects and Methods
Explore the JavaScript objects and methods you can utilize in your custom actions at Objects and Methods for Custom Actions.
Sandbox for Testing
Custom actions provide an excellent environment for experimenting with new code and testing queries. For example, check out how DayBack's Jason Young uses custom actions to console log query results in Testing SOQL Queries in DayBack Calendar.
Draft Mode
For testing App Actions or Event Actions, we recommend using Draft Mode. This mode allows you to make custom changes what are only active for your user session. This mode is great for testing code changes without affecting other users. Drafts and be saved, disabled, reenabled, and then applied to production when your code changes are ready for production user.