DayBackForFileMaker

Multiple Sources

How can I show records from more than one table in the same calendar?

Overview.

Traditionally a portal can only show records from one table occurrence, though it can include fields from other table occurrences related to the one the portal is based on.

DayBack, however, can include events from completely unrelated tables--each of which becomes a "data source" for the calendar. In this way you might have one source be an events table holding things like followup calls, meetings, etc. And have a second source for your jobs table where you show job due dates on the calendar.

The calendar ships with an example second source, a To-Do List, to show you how this works. You can toggle this second source off and on by visiting the "Calendars" tab in the calendar's left hand sidebar.

You can even have multiple sources from within the same table: if, for instance, you had a job due date in your jobs table and a followup date in your jobs table, you'd create those as two separate sources.

Note that having multiple sources can show up in the calendar's speed as there are more records to draw, and additional Find requests to perform: displaying fewer events at one time will always be faster. So you can have as many sources as you want, but try not to show them all at once by default.

How does the calendar decide which source to use for a new event?

First, if there is only one source showing, when you create an event the calendar will create it in that source.

When multiple sources are showing we look to see if the "default sources for new events" is one of them. If it is, we create the event in that source. You can specify this default source toward the top of the script "Load Calendar Settings - On Startup --- Edit Configuration Here ---".

If this default source is not one of the ones showing, we create the event in the first source showing.

So that's what happens when you just ask to create an event without specifying anything further: that is, when you double-click in the calendar. The calendar does, however, have an API that will let you make your own "+" button to create events in any source you want. You can use this to make a "new todo" button, for example. You'd do this by calling the script "Create Edit Delete Event ( SourceNo )..."

Read the comments at the head of that script to learn more about how to use it to make new events.

Creating a New FileMaker Source

Each source in the calendar is represented by a layout. You'll see a couple of these layouts in the calendar's example file: they are names "Source No 1" and "Source No 2". Any new sources you create will need a layout named the same way.

Here is how you'd create a new FileMaker source...

1. Duplicate the "Source No 1" layout and rename it Source No 3 (or your next unused source number).
2. Enter layout mode, then layout setup and base this new layout on the table you'd like to show records from. In this example, we'll call this "Orders"
Note that you may want to make our Events table a child of your orders table so that you can see multiple events per order. Making "orders" a source in itself is best for showing a singular fact about each order (like a due date) in the calendar.
3. While still in layout mode, visit each of the configuration tabs and enter the details or map fields specific to your source. Enter browse mode when you're done and review each tab for errors. Remember how you had to add a couple fields to your events table when you first integrated the calendar? You'll have to add the same fields to this table (to "Orders" in our example) in order to complete a few of the required fields. Best to review these fields now: take a look at step 2 in our integration instructions to recall these fields and step 2.1 to get a recap of editing the necessary calcs.
You'll also want to add the following auto enter calc to your TimeStart field (if you don't have a time start field, create one). Same thing with TimeEnd--make one and use this auto-enter calc:
Case (
Self = Time ( 24 ; 0 ; 0 ) ; Time ( 24 ; 0 ; 1 ) ;
Self = Time ( 0 ; 0 ; 0 ) ; Time ( 0 ; 0 ; 1 ) ;
Self > Time ( 24 ; 0 ; 0 ) ; Self - Time ( 24 ; 0 ; 0 ) + 1 ;
Self )
Make sure you uncheck the "Do not replace existing value" checkbox. This Auto-Enter option is needed if you want events to be able to start or end at midnight.
3.1 When you're editing the field "DBk_WebViewerSource" note that the first variable declares which source number this data is for: be sure to change that to the source number for your table ("3" in our example).
4. Edit the script "Load Calendar Settings - On Startup --- Edit Configuration Here ---" and find the comment "Which sources are active by default". If you want your source to be shown in the calendar at startup, add its number to the List () function after that comment. If you don't do anything here your source will show up as a possible source on the Sources tab, but its events won't show in the calendar unless a user elects to click on that source.
5. If you don't already have form view and list view layouts for your new source, duplicate the layout "Action - View Event" and use that to make a new layout based on your new source's table occurrence. Switch the layout's table and fields to all come from your new source's table occurrence. You can come back later and duplicate the Event-List layout as well to make a list view for this source. You'll reference this source's form view layout in one of the script variables in the next step.
6. Now edit the script "Load Source Settings at Startup --- Describe Your Sources Here ---" where you'll see a block of a dozen lines for each source. Duplicate this block for your new source by copying and pasting an existing block back into the script: begin your block by testing for the source's layout name as we do, testing for "Source No 3". Then edit each of the lines in the block, taking the script comments as instructions.
That's it! As you did with your first source, you may want to add some custom actions (buttons to act on this source from within the calendar's event details popover). Learn how to add actions here: Custom Actions.

How do I determine which sources show up by default?

Edit the script "Load Calendar Settings - On Startup --- Edit Configuration Here ---" and find the comment "Which sources are active by default". If you want your source to be shown in the calendar at startup, add its number to the List () function after that comment. If you don't do anything here your source will show up as a possible source on the Calendars tab, but its events won't show in the calendar unless a user elects to click on that source.

Can I have multiple sources from the same base table?

Yes! You might want to, for example, display two distinct sets of Dates/Times from a Jobs or Projects table. (However, in many cases, using a related table to handle multiple dates makes the most sense. For more info on this, see step 1 of Quick Integration).

If you haven't already, follow the Integration instructions to add a source using your first set of Date/Time fields. With the one source working, duplicate the "DBk_WebViewerSource" field twice (one for each source). With the To-Do List set as Source Number 2, let's call these fields "DBk_WebviewerSource1" and "DBk_WebviewerSource3".

Since you've already set up the first source, DBk_WebviewerSource1 does not need any modification. Now, map the appropriate date and time fields in the DBk_WebviewerSource3 calc. Make sure that the sc_sourceNumber variable matches your new source number. Next, replace the entire contents of the original/existing DBk_WebviewerSource calculated field with the following case statement:

Case (
$sc_SourceNo = 1 ;
DBk_WebViewerSource1 ;
$sc_SourceNo = 3 ;
DBk_WebViewerSource3 ;
)

We also need a set of DBk_TimestampStartCalcNum and DBk_TimestampEndCalcNum fields for each source. Rename the fields by appending "1" to each field name (these will continue to be used for source 1). Then duplicate them, naming the duplicates DBk_TimestampStartCalcNum3 and DBk_TimestampEndCalcNum3. In these calc fields for source 3, map the date and time fields that correspond with this source.

With the fields set up, completing the addition of the second source is much like adding a source from another table (although a bit easier). Duplicate the Source No 1 layout and rename it Source No 3. Map the date, time, and DBk_TImestamp fields that correspond with this source. Since the same base table occurrence is used for this source, no other fields need to be remapped, unless you have Status or Resource (or other) fields uniquely corresponding to these dates.

Lastly, update the Settings scripts as described in steps 4 and 5 above, and run the Upon Opening script. Your records from this table will be available on the calendar twice!

How can I delete a source or hide it from some users?

All you need to do is change the name of the Source No 2 layout to "Unused No 2". And then quit FileMaker and reopen DayBack.

It can be a little confusing because the source descriptions are stored as global variables and these can hang out, once defined, until you close the solution and reopen it. But DayBack's script "Load Source Settings at Startup --- Describe Your Sources Here ---" looks for the layout's containing "Source No" in their name so changing the name short circuits this while leaving the code in place so you can easily add that source back if you'd like.

If you wanted the source to only show up for some users, you could wrap the "Source No 2" section in the script "Load Source Settings at Startup --- Describe Your Sources Here ---" in an If() statement so that source was only described for some users.

Can I toggle on/off sources within a script?

This is not currently a built-in option, but you *can* override which sources get loaded into the calendar. Since this customization won't actually toggle the active sources in DayBack's sidebar, it's best implemented only when you've added a custom sidebar.

First, within the "Load Calendar Settings - On Startup" script, make sure all your sources are set to active (see "How do I determine which sources show up by default?" section above).

Then, modify the "Event Find" script by adding a Set Variable step just after the $assign_parameters Set Variable step. This step should set the $$sc_SourcesActive variable to the list of your desired active source numbers, so this will depend on how you're tracking/choosing which sources should appear active.

With these changes added, you'll be able to script which sources are "active" without needing to manual toggle sources on the built-in calendar sidebar.

(855) SEEDCODE
[email protected]
Follow us: