2 Replies Latest reply on Jul 16, 2013 11:20 AM by afterhours

    Managing Text Formatting in multiple fields, stripping or modifying

    afterhours

      Title

      Managing Text Formatting in multiple fields, stripping or modifying

      Post

            

           Crafting a MSDS solution.  When populating records by cut/paste from resources, the formating of the original is retained, rather than the desired formatting assigned to each of the fields.  There are 150+ fields involved at present.  For readability and consistency, I'd like to have a way to strip the formatting from the text fields on a per-record basis.

           One way to insure uniform formatting is to use the autocalc in the option portion of defining the text field, with a self-referenceing calc [TextFormatRemove ( field_A )], but there are times where some reformatting may be desired, or retaining some formatting.  My desired solution to keep things flexible is to craft a script that would reformat a record on command (not forced as the above calc'd option achieves).  And the coder in me wants to write a script that would loop through all of the presented fields in a layout.

            

           Is there a way to step through each field in a particular existing record to 'update' the format (remove any format that came in via cut/paste from another source)?   I've played around with some scripts, isolating the record of interest with the old

           show all records

           omit record

           show omitted

           trick to show only the one record.  I've written a few scripts to try and attempt a more elegant method than brute forcing each field of interest using the Replace Field Contents tool have failed.   Ideally, I'd love to craft a way to start at the first field (in Tab order) of a layout,

           set a page variable for that field's name using Set Variable [$FieldToFormat, Value Get (ActiveFieldName)]

           then remove the formatting for that field, and loop through the next tab order field and repeat.   Ultimately work my way through an entire data entry form to resolve all formatting snafus.   Thus far, I've been stuck since using even simple tools like:

           Set Field By Name [$FieldToFormat, TextFormatRemove (GetField ($FieldToFormat,))]

           doesn't work as I expected.   Formats remain.  Bummer.

           Any ideas of what I'm overlooking?

           Filemaker Pro Advanced 11, OSX 10.7.5

        • 1. Re: Managing Text Formatting in multiple fields, stripping or modifying
          philmodjunk

               Instead of a looping script, consider using Replace Field Contents with the calculation option to remove/modify text formatting. Perform a find first to pull up a found set of just those records where you want to do this.

               Your auto-enter calc can be modified in two ways:

               TextFormatRemove ( Self ) allows you to copy and paste the same expression into the auto-calc dialog for mutliple fields without needing to edit the names. And you can use a more sophisticated calc if you want the formats to be stripped selectively:

               If ( OverrideField ; self ; TextFormatRemove ( Self ) )

               Then, OverrideField can be set up as a number field with a single value check box that enters a 1 if clicked. When the user wants formatting to be retained they click the check box and then paste or format the text in the field.

               

                    Set Field By Name [$FieldToFormat, TextFormatRemove (GetField ($FieldToFormat,))]

               

                    doesn't work as I expected.   Formats remain.  Bummer.

               That would indicate that the value of $FIeldToFormat did not contain the correct text to successfully reference the desired field. The text in that variable needs to be in the format: TableOccurrenceName::FieldName. If you put just the name of the field there and left out the rest, the script step fails to make any changes to any data.

          • 2. Re: Managing Text Formatting in multiple fields, stripping or modifying
            afterhours

                 Phil,

                 Thanks for the reply.   Wow, how did I overlook the obvious re table/field parameter.   Must be holding out from my FMP6 days.  I didn't reference the table properly, as you gently pointed out.  After some play, it worked fine.

                 I'm trying to avoid the auto-calc option in the field definitions so I can leave individual records open to unusual formatting.  I can't foresee needing that, but who knows how my client will want to tweak their MSDS entries.  Something as simple as using bold or underline to emphasize parts of an individual section entry.

                  

                 Works like a charm.  No other records were harmed in the process -- only the one being viewed.  All formatting stripped.