6 Replies Latest reply on Jun 19, 2015 1:19 PM by koenraadb

    Color-formatting text within large text field - using script

    koenraadb

      Title

      Color-formatting text within large text field - using script

      Post

       

      Hi,

      Although I've done my share of programming in another life, I'm a newbie to FM Pro. I hope someone can help me with this.

      I am currently doing a large medical literature review. In order to make it easy for the reviewer to spot relevant text, I'd like to preformat the 'abstract' field, which typically contains a few hundred words. For instance, when searching for 'cancer', I'd like to be able to make each occurrence of the word 'cancer' bold and red, so it stands out and allows the reader to get to the relevant sections quickly.

      I have not been able to find scripts or functions that do that. Does anyone have a suggestion?

      Thanks!

       

        • 1. Re: Color-formatting text within large text field - using script
          SteveMartino

          You could instead try setting the field where the text you like to change with conditional formatting.  For example, if you use a field for your searches, in this case a global field, that triggers a search script, in the field  you are searching you can create a calculation for conditional formatting, i.e

          PatternCount(Self;Products::gPortal_Sort) 

          Self is used so you can put this calculation in any field--you could also just use the Table::field_name. This the field you want to change the color on.  Products::gPortal_Sort is the drop-down field you use for the search, that trips the search trigger

          Then you select 'bold' and pick a red color for the formatting. 

          So when the word in the search field is cancer, everyplace in the text body where the word cancer is, will be bold and red.  It may need a refresh script step, but the search should cover that.

          Edit:  This advice is wrong as it will change all the text in the field, as pointed out by Phil (see below).  I wont edit/delete the post above, otherwise it might create confusion.

          • 2. Re: Color-formatting text within large text field - using script
            philmodjunk

            uhh Steve,

            Do you not realize that your method formats the entire text field as bold, red and not just instances of the search text within it?

            You can put a calculation field on your layout with something like this expression:

            Let ( [ ST = YourTable::gSearchText ;
                       uST = Upper (ST ) ;
                       lST = Lower ( ST ) ;
                       pST = Proper ( ST )
                     ] ;
                     Substitute ( YourTable::ParagraphText ; [ ST ; TextColor ( ST ; RGB ( 255 ; 0 ; 0 ) ] ; [uST  ; TextColor ( uST ; RGB ( 255 ; 0 ; 0 ) ] ; [ lST ; TextColor ( lST ; RGB ( 255 ; 0 ; 0 ) ] ; [ pST ; TextColor ( pST ; RGB ( 255 ; 0 ; 0 ) ] )

            The above calculation just changes the text color to be red, but you can combine the textcolor function with other textformatting functions in order to apply additional text styles.

            The nasty detail here is that substitute is case sensitive. What I've done is substitute for the most likely capitalizations, substituting for text capitalized exactly like the search text, text that is all caps, all lower case and text that is only the first letter capitalized. If there is some idiosyncratic capitalization that does not match any of those, it will not appear in red.

            Note also that if your search text where "apple", the first 5 letters of "applesauce" will also appear in red.

            • 3. Re: Color-formatting text within large text field - using script
              SteveMartino

              uhh Phil...........now I do....lol  Thanks.  Yeah I use this when searching for products in a portal, and yes the fields are only one word..

              • 4. Re: Color-formatting text within large text field - using script
                koenraadb

                Hi Phil,

                Many thanks for your answer, which put me on the right way. There were some parentheses missing in the formula but once corrected, it worked. With bold feature added, it now looks like this:

                Let 

                    [ ST = "stringToFormat" ;
                           uST = Upper (ST ) ;
                           lST = Lower ( ST ) ;
                           pST = Proper ( ST )
                    ] ;
                         Substitute 
                         ( 
                             Table::FieldToSearch ; 
                             [ ST ;  TextColor (  TextStyleAdd (ST; Bold) ; RGB ( 255 ; 0 ; 0 ) )] ; 
                             [uST  ; TextColor ( TextStyleAdd (uST; Bold) ; RGB ( 255 ; 0 ; 0 ) ) ] ; 
                             [ lST ; TextColor ( TextStyleAdd (lST; Bold) ; RGB ( 255 ; 0 ; 0 ) ) ] ; 
                             [ pST ; TextColor ( TextStyleAdd (pST; Bold) ; RGB ( 255 ; 0 ; 0 ) ) ] 
                         )
                )

                 

                There seems to be a little glitch, though, in that most of the time this works correctly, but sometime the field returns a number preceeded by a period. If you then click in the field, the text shows correctly (including formatting). Not sure what that would be.

                Thanks again!

                Koenraad

                • 5. Re: Color-formatting text within large text field - using script
                  philmodjunk

                  Make sure that Text and not Number is specified as the calculation field's result type.

                  • 6. Re: Color-formatting text within large text field - using script
                    koenraadb

                    Sir,

                    You are so right. Evrything works fine now.

                    Thanks!