Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Dynamic Find/Replace "merge" fields in Text field

Featured Replies

  • Newbies

I have a Text field that will have "merge" fields. I want to replace them with actual field values, but I don't want to have to add a IF/END IF and Find/Replace script line for each "merge" field.

For example:

Dear <<First_Name>>:

Thank your for your donation of $<<donation_amount>>.

---------

These "merge" fields may change depending on the content of the letter. I would like to be able to replace all the "merge" fields with field names that are represented between the "<<" and ">>". I'm looking for a way to scan through the whole text and whereever it sees "<<" and ">>" to replace that value with the field name between them. So, in this example (and there would be different ones) I would replace <<First_Name>> with the value in the field [First_Name] and the same with <<donation_amount>>. I have created a script to search for each one manually by creating an IF statement for each possible value in this field. This seems too clumsy to me especially if I want to add new merge fields on the fly. Any advice out there would be greatly appreciated!

Thanks,

Dan Gronwald

[email protected]

Make your text field a calculation field then enter your paragraph like such as the calc.

"Dear " & First_Name & ":" & "

I made a custom function to do this last summer:

http://www.fmforums.com/threads/showflat.php?Cat=0&Number=120434

Although this was for version 7, perhaps the idea could be translated to a scripted approach in FM6.

If not, there's a way to do this with a calculation field, though you'd need to explicitly say what the field substitutions are:

ResultField (calculation, text result) = substitute ( substitute ( substitute ( SourceField, "<<First_Name>>", First_Name), "<<Last_Name>>", Last_Name ), "<<donation_amount>>", donation_amount )

  • Author
  • Newbies

Thank you both for your speedy replies. Since I'm using FMP v.6 I couldn't use the function option. And, I didn't want to use the Calculation field option because I have dynamic letters that use different tag fields depending on the type of letter, etc.

However, I was inspired by both and came up with a workable solution. By adding 3 dummy fields to temporarily hold the tag name, field name, and field value I'm able to parse through the letter text and do Find/Replace whereever there's a <<tag>>. It works great.

Go to Field ("Letter_Text")

If ("PatternCount((Letter_Text, "<<") > 0)

Loop

Set Field["tag_holder", "Middle(Letter_Text , Position( Letter_Text, "<<",

1, 1) , Position( Letter_Text, ">>", 1, 1) -

Position( Letter_Text, "<<", 1, 1) + 2)"]

Set Field["fldname_holder", "Middle(Letter_Text , Position( Letter_Text,

"<<", 1, 1) + 2 , Position( Letter_Text, ">>",

1, 1) - Position( Letter_Text, "<<", 1, 1) -

2)"]

Set Field["fldvalue_holder", "GetField(fldname_holder)"]

Perform Find/Replace [No dialog, "tag_holder", "fldvalue_holder", "Replace

All"]

Exit Loop If ["PatternCount(Letter_Text, "<<") = 0"]

End Loop

End If

thanks,

Dan Gronwald

The simplest method I've found to do this in FM6 is to use nested Substitute functions like this:

Substitute(Substitute(Substitute(Substitute(

Substitute(Substitute(Substitute(Textfield,

"<<Field01>>",Field01),

"<<Field02>>",Field02),

"<<Field03>>",Field03),

"<<Field04>>",Field04),

"<<Field05>>",Field05),

"<<Field06>>",Field06),

"<<Field07>>",Field07)

You just have to set it up ahead of time for whichever fields you want to allow your user to access.

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.