14 Replies Latest reply on Nov 5, 2014 12:31 PM by mikebeargie

    Changing a fields fill colour via another button(text field)

    samcourtenay

      Hi,

       

      I'm new here. Using FM 13 Pro. Developing my first database (well copying and cleaning up an old one really)

       

      I have a field I would like to change from a white background to a light red colour once it has been accepted. The field I need changed is called "Item 1:"

       

      I have created a text field next to "Item 1:" that when clicked it runs a simple script that inserts the text "accepted" into itself, then also copies the contents from "Item 1:" and moves it to another layout field "Item 1A: where I print the job sheets out.

       

      I have attached an image of the fields to be clear.

       

       

      I realise I could do this with conditioning formating by telling my accept script to add a random character to "Item 1:" and then conditionally format "Item 1:" to fill background if it contains that character. But I would much prefer the text in "Item 1:" not to change at all if possible.

       

      Is it possible via a calculation? Any help would be a huge help, thanks in advance.

        • 1. Re: Changing a fields fill colour via another button(text field)
          erolst

          samcourtenay wrote:

          I have a field I would like to change from a white background to a light red colour once it has been accepted.  The field I need changed is called "Item 1:"

           

          I have created a text field next to "Item 1:" that when clicked it runs a simple script that inserts the text "accepted" into itself,

           

          That's a bit confusing …

           

          You want to change the background colour if the record (job?) has been accepted; and if it has been accepted, you let (among other things) a script insert the text "accepted" into a flag field …

           

          So why can't you use a CF condition of MyTable::myFlagField = "accepted"?

          • 2. Re: Changing a fields fill colour via another button(text field)
            mikebeargie

            Stick with conditional formatting, create a flag field for storing your "accepted" status. Also, I'd suggest naming the description field on your layout in the inspector so you can refresh it later.

             

            The easiest way to do this is with a number field and a boolean, EG "f_accepted".

             

            Basically, your "accept" button script would be:

             

            Set Field [ table::f_accepted ; "1" ]

            Commit Records

            Refresh Object [ Description Field Layout Object Name ]

            ---whatever other actions you need to do

             

            Bonus, use FM13's new "hide object when" feature to completely hide the "accept" button if f_accepted = 1. This would also make it easier to spot "accepted" records.

            • 3. Re: Changing a fields fill colour via another button(text field)
              samcourtenay

              Thanks for the rapid responses!

               

              I forgot to mention I have 12 line items, my customers accept individual items so it's the fields that are accepted not the entire record.  These items are then copied to another layout so only the accpeted items are printed on the job sheet and then processed for invoicing.

              Here's another image to help explain.

              Untitled-1.jpg

              • 4. Re: Changing a fields fill colour via another button(text field)
                mikebeargie

                There’s no difference. Make the flag field in the line items table, and script/conditionally format against that.

                • 5. Re: Changing a fields fill colour via another button(text field)
                  erolst

                  samcourtenay wrote:

                  I forgot to mention I have 12 line items, my customers accept individual items so it's the fields that are accepted not the entire record.

                   

                  I hope (and so does Mike, surely ) you're not implying that you're using fields like item1, item2 … item12, and accepted1, accepted2…accepted12, instead of a line items table?

                  • 6. Re: Changing a fields fill colour via another button(text field)
                    mikebeargie

                    oh yes, definitely, please tell us you have a related table of line items…

                    • 7. Re: Changing a fields fill colour via another button(text field)
                      samcourtenay

                      Yes I am using a heap of fields, I know it is messy but I have about 30,000 records to import and want to use the same field names to make it easier.

                       

                      I've basically made this databse in a week (needs to be up next week).  I am going to re-write the entire thing over the next few months but I just need to get this going.  This is just a little extra I wanted to add it's not a biggie, I was hoping I could add a line into my script like -Set Field "Item 1:" fill background red-  I just don't know the correct forumla.

                       

                       

                      The original database was made on FM 5 in about 1996!  So it has a lot of fields ...

                      • 8. Re: Changing a fields fill colour via another button(text field)
                        mikebeargie

                        You can only highlight field contents via calculation AFAIK. TextStyleAdd() is the function.

                        http://www.filemaker.com/help/11/fmp/html/func_ref3.33.99.html

                        Something like TextStyleAdd(table::description ; HighlightYellow) would highlight all the field contents. But you can’t control background color.

                         

                        Back to erolst’s point then, if you are importing the text field already and it contains a value of “accepted”, then why can you not conditionally format based on the field containing that value?

                         

                        EG a basic formula of table::field = “accepted”

                         

                        conditional formatting relies on boolean calculations, so if the above statement results in “true”, it will apply the conditional formatting.

                        1 of 1 people found this helpful
                        • 9. Re: Changing a fields fill colour via another button(text field)
                          erolst

                          samcourtenay wrote:

                          The original database was made on FM 5 in about 1996!  So it has a lot of fields ...

                           

                          FM5 already had full relational capabilities, so that's neither an excuse, nor an explanation … anyway, promise that your re-write will result in a prim&proper, normalized ProjectParent-LineitemsChildren structure!

                           

                          samcourtenay wrote:

                          I was hoping I could add a line into my script like -Set Field "Item 1:" fill background red-  I just don't know the correct forumla.

                           

                          CF doesn't work that way; a conditional format is triggered by a condition that evaluates to True, so you need to set a value that – directly or indirectly - brings about that result.

                          • 10. Re: Changing a fields fill colour via another button(text field)
                            samcourtenay

                            haha I promise I will tidy it up!

                             

                            I'm still learning this program but it is great fun.

                             

                            Thanks for the help I really appreciate it.  I will just use the highlight function for interim.

                            • 11. Re: Changing a fields fill colour via another button(text field)
                              keywords

                              Re: "Yes I am using a heap of fields, I know it is messy but I have about 30,000 records to import and want to use the same field names to make it easier". Oh dear! You have a bit of a mess on your hands I fear. As already pointed out, you really should have a separate line items table.

                               

                              Since you are importing records into a new DB anyway, please consider the following option; it will be much less work in the long run:

                               

                              1.     Create a separate line item table and include in it a foreign key field which you will use to link each line item record to its parent (I am assuming the current table has a unique ID field—if it doesn't, then create one before you do anything else). Also include any of the existing line item data fields you need to hold the data from your 30,000 reords—BUT PLEASE! only create one of each

                              2.     Create (you probably already have) a parent table with all the fields that are relevant to the parent record—and of course the ID field as noted above

                              3.     Import into the parent table all the relevant parent data

                              4.     Carry out a series of imports into the line item table so that you capture all the existing data that is currently spread across multiple fields—eg. Import 1: itemDescription1 –> lineItem::description, etc for other fields; Import 2: itemDescription2 –> lineItem::description, etc for other fields; Import 3: itemDescription3 –> lineItem::description, etc for other fields; etcetera, etcetera for as many fields as needed. IMPORTANT!—include in each of the import cycles the ID from the existing table (see 1 above) into the parent ID field in the line item table; this will enable each line item record to be linked back to its correct parent record.

                               

                              If you take tohe time to do that you will save yourself—if nothing else—the task of setting up "a heap" of identical field formatting for you multiple field instances; instead you will do this only once in your line items table.

                              1 of 1 people found this helpful
                              • 12. Re: Changing a fields fill colour via another button(text field)
                                mikebeargie

                                using the TextStyleAdd() function is possibly harder than conditional formatting, and you are messing with the actually stored data, not applying a mask like you are with conditional formatting.

                                 

                                You should normalize your data and simplify it, not convert and carry over bad development from 10+ years ago.

                                • 13. Re: Changing a fields fill colour via another button(text field)
                                  samcourtenay

                                  As a quick fix I ended up making the line items fields transparent and put new fields behind them with white backgrounds, when the accepted button is clicked it adds a character to the field and conditionally formats it to change background color (text same color so you can't see the characters).

                                   

                                  Messy but it works perfectly.

                                  • 14. Re: Changing a fields fill colour via another button(text field)
                                    mikebeargie

                                    With the conditional formatting formula, you can conditionally format any field based on the value of another field, there is no need to make one transparent and add the other field underneath.

                                     

                                    I’d recommend that you take a filemaker training series course, there’s numerous trainers around the country and I think you’d benefit greatly.

                                     

                                    I’d also recommend mentoring, which is where a certified and veteran developer works with you on a project and can rapidly increase your wealth of FileMaker knowledge in a short amount of time. A lot of FileMaker developers (myself included) offer this through their company.