Robert Kidd Posted March 2, 2006 Posted March 2, 2006 Hi Guys I'm working on a Mail Merge system to allow users to create template letters and use these templates to create letters to contacts. I've written a custom function to make the substituition of real data with the merge fields but I'm using it in a looping script and I'm sure it could be recursive. Any help much appreciated. MergeTest.zip
Ender Posted March 2, 2006 Posted March 2, 2006 Check this CF: http://www.fmforums.com/forum/showtopic.php?tid/120434
Robert Kidd Posted March 2, 2006 Author Posted March 2, 2006 Hi Ender I did check out your CF before I posted but mine is a little different in that the merge fields do not have to be the actual field names. The merge field table deals with the translation between merge field and the actual field name. I did this for 2 reasons... 1) My field names may not be clear to a user 2) I have the ability to concatenate fields together. eg. the merge field could be <> and the substitution could be Contacts::Address1 & Contacts::Address2 etc. Besides, it's really bugging me !
Ender Posted March 2, 2006 Posted March 2, 2006 My CF is a general way to substitute field names with their values. If you define calcs for those concatonated fields, or have the buttons insert each merge field, then the problem is solved. Since you want the CF know that the < > tag represents multiple things, and that <> really means Contact::Name, then what would be useful is if the CF can refer to the merge table to see what the real field names are that should be used, but I'll have to think a little about how to do this.
Robert Kidd Posted March 3, 2006 Author Posted March 3, 2006 Hi Ender My CF does what I need it's just a the moment I have to loop my script to pass it new parameters to make each substitution in turn.I'm SURE this could be recursive, one parameter just needs to increment by 1 until it reaches a known value. I can pass all the info it needs in one go but just can't figure how to get it to call itself ( or at least call itself and then stop again ! ) Thanks for your help
Ender Posted March 3, 2006 Posted March 3, 2006 (edited) To make your CF iterate through all the merge substitutions, make it recursive with the stopping condition being the number of merge values remaining = 0. Like this: //Merge ( body; mergeArray; substituteArray ) = Let( values = ValueCount(mergearray); Case(values > 0; Merge(Substitute(body; LeftValues( mergeArray; 1); Evaluate(LeftValues( substituteArray; 1)) & ¶ ); RightValues(mergeArray; values-1); RightValues(substituteArray; values-1)); body) ) Edited March 3, 2006 by Guest Fixed for FM7 compatiblity.
Recommended Posts
This topic is 6838 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now