Writing a Script to Create a Custom Report

This extension is a tutorial on writing scripts to create a custom report. The simple report looks at "all" or "selected" family records and calculates the average age for the father and mother when they got married and when their children were born. The results are displayed in a GEDitCOM II report window or output to an MS Word document. All scripts in this extension generate the same report but using different scripting methods.

Script Logic

The flow chart for scripting is the same for all languages. The key script sections in the flow are listed here in generic terms. You can then see more details on each section for each language by refering to the Internal Scripting, AppleScripting, or Python scripting tutorials.

Preamble
The first step it to intialize the langauge and to verify the extension is compatible with current version of GEDitCOM II. For example, if a script uses commands that only became available in version 3.0, the script should abort for someone that has not updated to at least that version. Finally, all report scripts read data in a genealoigy document. If no document is open, the script should explain the problem and then exit.
Choose Records to Analyze
This sample report can analyze "All" family records or just the currently "Selected" family records. The "User Option" scripting command provides a dialog box that lets the user decide.
CollectAges Subroutine
This subroutine processes the choosen family records and for those that have valid dates, does age calculations needed for output to the final report. The logic is the same for all languages but the syntax changes:
  1. For each family record find marriage date as a serial day number (SDN). A serial day number assigns dates to numbers starting with 1 back around 4000 B.C.. Serial day numbers are ideal for date calculations such as finding years between two dates. All SDN methods return 0 if a date us unavailable or if the date is not formatted correctly. Calculations when needed SDNs are zero are skipped.
  2. Get birth SDNs for husband and wife. If either is known and marriage data is known, calculate their age on the marriage date and add to global variables.
  3. Go through each child in the family. If any child has a valid birth date, calculate age of father and mother (if they have valid birth dates) when the child was born. Add the result to the global variables.
WriteToReport
Once all data are collected, this section formats the result into a small table for display in report window. Most scripts format the report using html elements and then opens the report in a GEDitCOM II window. One sample script instead outputs the report to an MS Word document.

This Tutorial's Scripts

To see the scripts covered in this tutorial, open this extension in the GEDitCOM Editor (which you can do in GEDitCOM II by hold down the option key while selecting it). The opened CreateReportTutorial.gplug extension has complete scripts for each language and each one has a short tutorial in this documentation window (click the script name to see the tutorial):