New Item

How does the "new item" button work?

The script "Create New Item" will create new records in your data tables in the following circumstances:

  • When an item is selected, clicking "new item" will make a child of the selected record.
  • When no item is selected we attempt to make a new top-level record. But we can only do this if the hierarchy is showing all top-level records. So when Example One is set to 15 or 300 we can't make new-top-level records. This won't be a problem in your file as you'll like be showing all records.
  • Similarly, when the hierarchy is filtered as in Example Two we can make a child of a selected record but can not make new top-level records.

Note that creating new top-level records is faster when there is no formatting applied (when neither Outline or Legal formatting is applied). When such formatting is applied, we need to refresh the whole hierarchy when we create a new item.


In order to create new items from the hierarchy using our "new item" button, make sure you've taken these steps when integrating the hierarchy with your own file:

  • Make sure you have the key fields for each table on your "HierarchyLevel..." layouts as described in the integration notes in step 9.
  • Be sure at least one of your fields on each tab of Example Three has the object name "Level...FirstField" where "..." is the level of the tab you're on. This is described in the notes on integrating Example Three.
  • Make sure the your logged in users have the rights to create and edit records in your data tables.

Adding more info to newly created items.

The hierarchy is written in such a way that it can create new related records in your data tables. This is done in the script "Create New Item" and is written very generically, so it doesn't need to be edited in order to work with your tables.

Of course you may need to add more information to a new record than simply creating it and linking it to its parent. If you do, edit the script "Create New Item" and find the comment beginning "Set other values as needed...". Add any set field steps you may need immediately following that comment. Remember that we use the same script here regardless of what kind of record we're creating, so you'll likely need to test for the record type first before you set any record specific fields. You can use a test like this:

Patterncount ( Get ( LayoutTableName ) ; "1" )

That would return true if we're on data level 1, making a company record, etc. Testing for levels in this way would let you add information specific to any level of the hierarchy.

Deleting selected items.

Example Three provides a button for deleting a selected item. This works great: if an item is selected, you can delete it. However, we're currently preventing you from deleting items that have children beneath them. (We do this by testing the open items global variable, not by testing for related records directly, so what we're looking for is, "did the item have children when the hierarchy was last drawn?")

Note that you can use FileMaker's access privileges to prevent deletions in this and other circumstances in addition to what we've done in the hierarchy.

If you want to allow the deletion of records which have children, you'll need to make a couple changes:

1. Make sure the the "data" relationships in the hierarchy have "Delete related records in this table..." checked on the right side of each relationship: for example, in the one between HierarchyDataLevel1 and HierarchyDataLevel2:

2. Edit the script "Delete Selected Item" and find the comment "If Item has children don't delete." Delete this comment, the next one, and the 5 lines below them including the If() statement and everything between it and End If.

That's it.

[email protected]
Follow us: