8 Replies Latest reply on Dec 26, 2015 9:06 AM by schamblee

    Parse a text field and replace <<txt>> with the contents of a field

    jared944

      Hello everyone,

       

      I want to create a letter customized to the recipient based off of the contents of various keyfields. I have a field named Letter::Text that contains a letter template:

       

           Dear <<Name>>, I saw you on <<Date>>...

       

      The script will replace <<Name>> with the contents of a field, in this case Data::Name_First (Garry). I want to be able to update the list of replacement terms and their associated field. To do this I created a table with two text fields, Repl::Target_Word and Repl::Source_Path. The table would look like this:

       

      <<Name>>          Data::Name_First

      <<Birthday>>      Data::Birthdate

      <<Date>>            Letter::Date

       

      I have a script that looks at each field as an object and loops to change the target word with the replacement phrase :

       

      Loop

        ----------- / / -----------

        Go to Object [ Object name: "Source" ]

        Set Variable [ $Source ; Value: Get (ActiveFieldContents) ]

        Go to Object [ Object name: "Target" ]

        Set Variable [ $Target ; Value: Get (ActiveFieldContents) ]

        Go to Object [ Object name: "Text" ]

        Insert Calculated Results [ Select ; Substitute ( Get (ActiveFieldContents) ;  $Target  ;  "<<" & $Source & ">>"    )

      ----------- / / -----------

      End Loop

       

      The problem I have found is that the $Source file is always referenced as a text string and not a path to a field. If I want to turn <<First Name>> to <<Garry>>, I instead process it into "<<Data::Name_First>>".

       

      Does anyone have a better way to replace text in a field based off of the contents of other fields? Im not sure how I can reference different fields in the database using one field in multiple records. There must be a better way to do this.

       

      Thanks!

       

      Jared