Merge Letter Templates

by Matthew Leering

Version: 1.1
Release Date: November 21, 2015
Author: Matthew Leering



In short, this is a module that will allow developers to define merge letter variables which can be inserted into merge letter templates that users are able to create. It uses a single table that serves double duty as both storage for template data, and also for handling the virtual list of merge letter variables.  I’ve tried to make this as easy to integrate as possible, so hopefully your experience with this module is a good one.


Version 1.1 Updates Include:

  • Updated Readme (Reference to Configuration script was mis-labeled, another step wasn’t verbose enough in its explanation) –> Thanks Mike!
  • Fixed bug with Configuration script –> incorrect layout name was hardcoded
  • Updated how variables get dynamically created
  • Introduced new way of using get variables that evaluate at runtime –> Use {{GetFunctionName}} syntax similar to merge functions used on layouts
  • Allowed for the usage of string literals as substitution text –> Can also have system generate these strings onInitializeModule (not necessarily runtime)
  • Updated configuration to show examples of all 3 types of substitution values (fields/strings/GetFunctions)



How To Install

  1. Copy “ModularMergeLetterVariables” Table to your solution
  2. Reset auto-enter serial to 1
  3. Recreate Relationship to the “ModularMergeVariables_Self” table
  4. Copy Scripts To Your Solution
  5. Copy All Layout Objects From “ModularMergeLetterVariables” Layout Into the “ModularMergeLetterVariables” Layout That Should Have Been Automatically Created In Your System
  6. Modify “Configuration” script so that it will point to the correct layout
  7. Make sure the “Initialize Module” script gets called prior to running the “Return Merged Text” script. (I opted to run the “Initialize Module” onFirstWindowOpen for the purpose of this demo)
  8. *Optional* You Might Want To Create A Value List Like The One That Exists In This Demo File

How To Implement

  1. Perform Script “Return Merged Text” passing your templateContent as a parameter.
  2. Bring the user to a layout that displays the results of the “MERGEDTEXT” field in a letter-style layout


Download Merge Letter Templates

11 responses to “Merge Letter Templates”

  1. Mike says:

    This looks very cool! Thank you!

    One clarification, in step 6 you cite an “Editable Configuration” script. There is none. This is however a “Configuration script. I assume this is what you are referring to.

    Thank you very much!

    • Thanks for the feedback, Mike.
      You’re right, the script that I reference in step 6 is actually now called “Configuration “. Thank you for pointing this out.
      I’ve updated the post, and will update the Readme in the module as soon as I get a chance to.

  2. Don Clark says:

    Great job, Matthew! I just posted this on FileMaker Pro Gurus and I’ve added to the Free FileMaker Example File LIst (

    Thanks for sharing this.


  3. Robert says:

    Thank you Mathew for the file –
    This may be a dumb question but how do you add new fields to the merge list in the template layout.
    i added a filed called “Bond”, in the config script, which will merge in the Template if I manually insert it
    but how do you get it into the available list of merge fields


    • No prob, Rob.

      In theory, all you really need to do is add a new call to
      Perform Script [“Add A Merge Variable”] in the configuration script (which it sounds like you’ve already done).

      If that’s been done, and everything was setup properly, then simply close/re-open the system, and you should be set!

      Hope this helps!

  4. Nuri says:

    Thank you Mathew.

  5. Lia McNeilly says:

    Hi Matthew,

    I implemented this last night and it worked; I was even able to create sample letters. When I came back to it today, it now says Unrelated Table and I’ve lost the letters that I created last night. I have deleted and redone the entire process, to no avail. I cannot figure out which piece I am missing this time, nor where it would have gone when I shut down my computer.
    Thank you for your help.

  6. TechFIsh says:


    Having some issues with expected behavior of the demo on FMPS 170.5. Perhaps my expectations are incorrect 🙂

    Here’s what to do to repeat:

    1. Open file
    2. Go to ‘Sample Contacts’ layout
    3. Show All contacts
    4. Click Generate Merge Letter > Select Letter > Merge


    500 merge letters would be created and shown.


    One merge letter is created and show for the first record.

    What am I doing wrong?



    • Hi TechFIsh;
      That is indeed the expected behaviour (to only produce one single merge letter).
      Keep in mind that this is just a demo.
      If you need it to create multiple merge letters, you would probably just want to wrap the example code in a loop.

      Something along the lines of:

      Go To Record (First)
      Maybe save as PDF?
      Go To Record (Next, Exit After Last)
      End Loop

      Hope this helps!

Leave a Reply

Your email address will not be published. Required fields are marked *