Get Resources and Statuses from FileMaker

Overview

By default, DayBack stores resources and statuses with its own settings. You can make new resources and statuses, make new folders, and change their sort order as shown here:

But you may already have FileMaker tables for your resources and statuses, so DayBack offers a way to pull these values in from FileMaker. You can pull all your values in from FileMaker or continue to have some resources and statuses stored in DayBack's settings. These scripts will let you base your filters and filter folders on your own FileMaker scripts, so you can do things like...

  • Load only the territories (resource folders) and direct reports (resources) for each sales manager as they log in;
  • Keep a complex list of equipment (resources) up to date in FileMaker instead of managing it by hand in DayBack;
  • User the same value list of project types (statuses) between DayBack and FileMaker.

Using FileMaker Tables for Resources and/or Statuses

DayBack ships with two examples to show you how to do this. 

Status Example: Send JSON to DayBack

Take a look at the FileMaker script "Sample Statuses - DayBack" that comes with DayBack. This example builds a list of statuses, status colors, and folders in JSON. Use the JSON in this script as a guide for how you should format your own JSON; either hard-code it as we're doing or loop through your own records (or your own value list) to build a similar JSON object. 

If you need help writing a script that builds JSON like this, we can write that for you as part of an implementation package.

To run this example, you'll head to admin settings and 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 with lets you call any FileMaker script from within DayBack. It takes the script name as its first parameter, then any script parameters, then the name of any callback function you'd like to run.)

Note that this action is set to replace any statuses you have with the contents of the FileMaker script. That's done in the first line that initializes filterItems and in line 11, the seedcodeCalendar.init line. The Resources example below appends the contents of the FileMaker script to any resources already there and you can see those two lines are different.

To use the code above for resources, change two things: 

  1. the name of the FileMaker script in line 3. Remember that this script needs to produce JSON in the form used in "Sample Statuses - DayBack".
  2. replace "statuses" with "resources" in line 11.

Resources Example: Send a Simple List to DayBack

This example is very similar except that it just takes a list of resources as its starting point. This means you don't have to make any JSON on your end, but it also means that you can't create folders for your resources. You'd need to pass in a JSON object like that in the statuses example (and use the status-example style script) if you want to create folders automatically.

Take a look at the FileMaker script "Sample Resources - DayBack" that comes with DayBack. You'll see that in line 12 it just assembles a list of resource names. You could do this in a loop, using ListOf(), or using ValueListItems().

You'll run this script by creating an app action with an "On Resources Fetched" trigger like this:

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();
});

Note since this action loads filterItems with the current content of 'resources', it appends the contents of the FileMaker script to any resources already in DayBack.

To use the code above for statuses, change two things: 

  1. the name of the FileMaker script in line 2. Remember that this script needs to produce a simple list of names in the form used in "Sample Resources - DayBack".
  2. replace "resources" with "statuses" in line 1.

Resources Example: Build resources from a table as JSON including folders, sort, selected status, and tags.

This example builds your resource filter objects in JSON format from a table in your file. It includes the folder structure, sort order, whether or not the status is selected, and tags.

You'll need to download the sample file here for this one: DayBack Calendar JSON Filters

There is a Resources table in this file that contains some sample filter values. You can import this table into your file to use them for your own filters.

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

You'll run this script by creating an app action with an "On Resources Fetched" trigger. You can download the code for this action here and paste it into your app action in DayBack: filtersJSON.js

There's also a sample Statuses table and script called "Sample Statuses JSON- DayBack" that can be used for Statuses. Just change the following in the app action to use it for Statuses:

  1. Point inputs.scriptName to your script name on line 30.
  2. Replace 'resources' with 'statuses' in 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 actionCallbacks.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.

There are some cases where you might want to update your resource or status list based on the date 

// 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 make publicly shared bookmarks that include resources or statues pulled from FileMaker, remember that your users won't have access to FileMaker and won't be able to pull statues and resources from your tables. Your bookmark will work, but recipients won't be able to filter it further because they'll see DayBack's stock resources instead of your own. We suggest locking the sidebar for shares in this case or removing the resources section with CSS.


Editing Resources and Statuses Created From Actions

Any filter items you create from actions like this are not stored in DayBack's settings and thus aren't editable in DayBack. You'll need to edit them, changing their color and sort order, in FileMaker in order to see changes in DayBack.


Sorting Resources or Statuses before they are Displayed

Since you can't edit dynamically-created items in DayBack, you can't sort them either without add a separate app action, or additional JavaScript code to sort the list after it is loaded. You can, however, provide a sort order in the JSON you send to DayBack. Add a new attribute "sort" in the form "sort: 2" (without the quotes). Note that if you pass in a sort for any one item you'll want to include a sort attribute for every item, including any folders.


Sorting Resources after they have been Loaded

If you do not specify a "sort" JSON attribute, DayBack will simply sort the resources in the order in which they come back in the JSON. If you prefer to sort them yourself in JavaScript, you can add the following After Events Rendered action, to add a resources.sort() call that re-sorts the list. In the following example, the list 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();
}

Locking Yourself Out with Custom Actions

If you write some really bad JavaScript, you can write an action that prevents DayBack from starting. You'll just see the blue loading bars run across the screen and you'll never get to the calendar. If that happens, close your FileMaker file (or navigate to another layout) and then return to DayBack while holding down the shift key and moving the mouse back and forth. That will cause DayBack to bypass any app-actions you've written and take you right to the settings screen where you can correct your action or turn it off.

(Turn your action "off" by unchecking the box next to "app" below the action.)


Sorting Resources in Salesforce

If you are looking for documentation on how to retrieve and sort resources in Salesforce, check out our documentation on Dynamic Resources and Statuses for Salesforce.