From SeedCode Documentation

SeedCodeHierarchy: NewItem

How does the "new item" button work?

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

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.

Requirements.

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:

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.

Retrieved from http://archive.seedcode.com/pmwiki/index.php?n=SeedCodeHierarchy.NewItem
Page last modified on October 10, 2008, at 06:39 PM