Get Resources and Statuses from FileMaker

Overview

By default, DayBack stores resources and statuses within its own settings. This allows you to create new resources and statuses, organize them into folders, and adjust their sort order as shown below:

However, if you already have tables in FileMaker for managing resources and statuses, DayBack provides a way to pull these values directly from FileMaker. You can choose to import all your values from FileMaker or continue using a combination of FileMaker and DayBack's settings for managing resources and statuses.

These scripts enable you to base your filters and filter folders on your FileMaker data, allowing you to:

  • Load only the territories (resource folders) and direct reports (resources) relevant to each sales manager as they log in.
  • Maintain a complex list of equipment (resources) up to date in FileMaker instead of managing it by hand in DayBack.
  • Use the same value list of project types (statuses) in both DayBack and FileMaker, ensuring consistency across platforms.


Using FileMaker Tables for Resources or Statuses

DayBack ships with two examples that demonstrate how to use your own FileMaker tables to manage resources and statuses.

Status Example: Send JSON to DayBack

One example can be found in the FileMaker script titled "Sample Statuses - DayBack," which comes with DayBack. This script constructs a list of statuses, status colors, and folders in JSON format. You can use the JSON structure from this script as a template for creating your own. You can either hard-code it as shown in the example or loop through your records or value lists to build a similar JSON object.

If you need assistance in writing a script to generate JSON like this, we can develop it for you as part of an implementation package.

Running the Example

To run this example, follow these steps:

  1. Go to the admin settings in DayBack.
  2. Create an app action with an "On Statuses Fetched" trigger like this:

Here's the code for that action:

// Trigger - On Statuses Fetched
// Prevent Default Action - Yes
// Do not enable this action for "Shares", only for App.

var filterItems = [];
var item;
dbk.performFileMakerScript('Sample Statuses - DayBack', null, function(result) {
  	if (result && result.payload) {  	
      	for (var i = 0; i < result.payload.length; i++) {
          	item = result.payload[i];
          	dbk.mutateFilterField(item)
    		filterItems.push(item);
    	}
    }
    seedcodeCalendar.init('statuses', filterItems);
	action.callbacks.confirm();
});

This code uses the dbk.performFileMakerScript() function, which allows you to call any FileMaker script from within DayBack. It takes three parameters: the script name, any script parameters, and the name of a callback function you'd like to run.

Key Points:

  • This action is set to replace any existing statuses with the contents of the FileMaker script. This is controlled by the line that initializes filterItems as an empty array, and line 11 that uses seedcodeCalendar.init to replace the statuses array with the new array of statuses.
  • The example below appends the contents of the FileMaker script to any existing resources, and you can see that the initialization lines differ.

To adapt this code for resources, change two things:

  1. Replace the name of the FileMaker script in line 3 with the script that generates your resource JSON.
  2. Replace "statuses" with "resources" in line 11.

Resources Example: Send a Simple List to DayBack

This example is very similar to the previous one but starts with the existing list of resources manually created within DayBack, which is then expanded by fetching additional resources from FileMaker.

Unlike the status example, you don't need to create a JSON object on your end. However, this approach has a limitation: you won’t be able to create folders for your resources. If you need folders, you'll want to use the JSON-based method described in the status example.

Start by reviewing the FileMaker script titled "Sample Resources - DayBack" that comes with DayBack. You'll notice that in line 12, the script simply assembles a list of resource names. You could achieve this in your own script by using a loop, the ListOf() function, or the ValueListItems() function.

To run this script, you'll create an app action with an "On Resources Fetched" trigger. Here's how to set it up:

Here's the code for that action:

// Trigger - On Resources Fetched
// Prevent Default Action - Yes
// Do not enable this action for "Shares", only for App

var filterItems = seedcodeCalendar.get('resources');
var item;

dbk.performFileMakerScript('Sample Resources - DayBack', null, function(result) {
  	if (result && result.payload) {  	
      	for (var i = 0; i < result.payload.length; i++) {
          	item = dbk.nameToFilterItem(result.payload[i])
    		filterItems.push(item);
    	}
    }
	action.callbacks.confirm();
});

Key Points:

  • This action appends the list of resources from your FileMaker script to the existing resources in DayBack. It does this by loading the current resources into filterItems and then adding the new resources from the script.

To adapt this code for statuses, change two things:

  1. Replace the name of the FileMaker script in line 2 with the script that generates your list of status names (See prior example screen "Sample Resources - DayBack").
  2. Replace "resources" with "statuses" in line 1.

Resources Example: Build Resources from a Table as JSON, Including Folders, Sort Order, Selected Status, and Tags.

This example demonstrates how to construct your resource filter objects in JSON format from a table in your FileMaker file. It includes features such as folder structure, sort order, selected status, and tags.

To get started, download the sample file here: DayBack Calendar JSON Filters.

This file contains a "Resources" table with sample filter values. You can import this table into your FileMaker file to use these values for your own filters.

Next, copy the FileMaker script titled "Sample Resources JSON - DayBack" into your file. This script loops through the Resources table and builds the JSON data to send to FileMaker.

To run this script, create an app action in DayBack with an "On Resources Fetched" trigger. You can download the code for this action here and paste it into your app action in DayBack: filters-json.js.

Additionally, there's a "Statuses" table and a corresponding script called "Sample Statuses JSON - DayBack" that can be used for statuses. To adapt the app action for statuses, make the following changes:

  1. Point inputs.scriptName to your script name on line 30.
  2. Replace 'resources' with 'statuses' on line 33.

Updating the Resource List After the Calendar has Already Loaded

If you'd like to update the list of resources in the sidebar after the calendar has already loaded, for example, in an "After View Changed" event action, you'll just need to add one line right after action.callbacks.confirm(); in the example action:

dbk.resetResources();

This function will reset and refresh the resource list based on the values you've just provided, without needing to refresh the calendar.

For instance, there may be cases where you might want to update your resource or status list based on the date. The following example retrieves the current view, and the current date, passing them to a FileMaker script that returns a distinct list of resources based on custom criteria: 

// Trigger - On Events Rendered
// Prevent Default Action - No

//Update Resources on Date Change

var filterItems = [];
var item;
var currentView = seedcodeCalendar.get('view');
var currentDate = seedcodeCalendar.get('date');
var resourceRefresh = seedcodeCalendar.get('resourceRefresh');

if (resourceRefresh){
  seedcodeCalendar.init('resourceRefresh');
}
else{
  seedcodeCalendar.init('resourceRefresh', true);
  dbk.performFileMakerScript('Sample Resources - DayBack', {view: currentView, date: currentDate}, function(result) {
      if (result && result.payload) {  	
          for (var i = 0; i < result.payload.length; i++) {
              item = result.payload[i];
              dbk.mutateFilterField(item)
              filterItems.push(item);
          }
          seedcodeCalendar.init('resources', filterItems);
          dbk.resetResources();
      }
  });
}

Considerations When Making Public Shares

If you plan on creating publicly shared bookmarks that include resources or statuses pulled from FileMaker, keep in mind that users without access to FileMaker won't be able to retrieve those resources and statuses from your tables. Although your bookmark will work, recipients won't be able to filter it further because they will only see DayBack's default resources, not your custom ones. To address this, consider locking the sidebar for shared bookmarks or removing the resources section with CSS.


Editing Resources and Statuses Created From Actions

Any filter items created via app actions aren't stored in DayBack's settings, so you can't edit them directly in DayBack. To modify these items, such as changing their color or sort order, you'll need to make those adjustments in FileMaker in order to view the changes in DayBack.


Sorting Resources or Statuses before they are Displayed

Because dynamically-created items in DayBack can't be edited or sorted directly, you'll need to either add a separate app action or include additional JavaScript code to sort the list after it is loaded. However, you can define the sort order within the JSON you send to DayBack by adding a "sort" attribute, like this: "sort: 2" . If you specify a sort order for one item, ensure you include a sort attribute for every item, including any folders, to maintain consistent ordering.


Sorting Resources after they have been Loaded

If you don't include a "sort" attribute in your JSON, DayBack will display the resources in the order they are received. However, if you prefer to sort the resources using JavaScript, you can add an "After Events Rendered" action. This action allows you to use a resources.sort() call to reorder the list. In the example below, the resources will be sorted alphabetically in ascending order:

// Load existing resources
var resources = seedcodeCalendar.get("resources");
// Set a variable that tracks that we only run this action only the 
// first time the Calendar's events are displayed
var resourceRefresh = seedcodeCalendar.get('resourceRefresh');
if (resourceRefresh){
	seedcodeCalendar.init('resourceRefresh');
} else{
  	seedcodeCalendar.init('resourceRefresh', true);
	// Sort resources in ascending alphabetical order
	resources.sort((a,b) => a.name.localeCompare(b.name));
	// Set the resources
	seedcodeCalendar.init('resources', resources);
	// Tell DayBack that the resources have been reset
	dbk.resetResources();
}

Avoiding Lockouts when Coding Custom Actions

If you write JavaScript that contains errors, it might prevent DayBack from loading properly. In such cases, you may see the loading bars repeatedly run across the screen without the calendar ever appearing. If this happens, close your FileMaker file (or switch to another layout), then return to DayBack while holding down the shift key and moving your mouse back and forth. This will call DayBack to bypass any custom app actions you've written and take you directly to the settings screen, where you can either correct the issue or disable the problematic action.

(To disable an action, uncheck the box labeled "app" below the action.)


Sorting Resources in Salesforce

If you're seeking guidance on how to retrieve and sort resources in Salesforce, refer to our documentation on Dynamic Resources and Statuses for Salesforce.