AnsweredAssumed Answered

Creating multiple related records via script

Question asked by jimb on Sep 12, 2011
Latest reply on Sep 17, 2011 by jimb


Creating multiple related records via script


I'm fairly new to Filemaker and am developing a database whose purpose is to support analysis of a set of student essays by expert raters. I'm using Filemaker Pro 11 Advanced.

The essay analyses occur at two levels: holistic, and segment-by-segment. An existing table in the database (Essays) holds information about each essay, and a related table (Segments) holds information about each segment (i.e., a sentence or phrase). When analysts select a record in a layout based on the Essays table, they see information about the selected essay and, in a portal, its related segments. By clicking on a "new analysis" button, they create a new record into which they can insert their analysis of the essay. The logic is one-to-many: an individual essay can be analyzed by multiple users, and each analysis is a separate record in an EssayAnalyses table.

So far, I've been able to script this button to create a new record in the EssayAnalysis table, linked to the particular Essay via its primary key (i.e., by using Set Variable to grab the EssayID from the Essays table, creating a new record in the EssayAnalysis table, and using Set Field to populate a foreign key field in the new record).

What I'd like also to be able to do is to have this script, at the same time, create multiple related records for segment-by-segment analysis information, in a SegmentAnalyes table. The end result should be to create a two-level structure of analysis tables -- EssayAnalyses and SegmentAnalyses -- that parallels the structure of the Essays and Segments tables. The analysis editing and viewing layouts would be based on the EssayAnalyses table, with SegmentAnalyses information accessed via a portal.

It's my understanding that to make this two-level creation of analysis records work, I'd need to do something like the following:

1. find the entries in the Segments table that have the same EssayID as the selected essay.

2. step through each of the matching records in the Segments table, grab its primary key (SegmentID) and create a new record with that SegmentID as a foreign key in the SegmentAnalysis table.

Trouble is, I can't figure out the logic that will enable me to do this. Is this possibly something that the 'Repetitions' feature of Variables would be useful for? Is a looping approach needed?

Thanks for any pointers,