11 Replies Latest reply on Nov 22, 2010 3:42 PM by yomango

    Scripting

    yomango

      Title

      Scripting

      Post

      Hello out there. I am in need of a help trying to do a script that takes information from a filed and posts it in a field with check box values. Here´s how the fields are set: field #1 reads world regions and has values for "Entire World", "US", US&Canada", "Latin America", "Asia" and "Africa", field #2 lists ALL the countries with a check box next to each name. 

      I want to mark field#1 with, let´s say "US&Canada" and have a script mark both check boxes in field #2. I have tried but filed #2 ends marked only with the last country name I have designed for the script. If I tell the script "once you see in filed #1  -US&Canada-, place text values on filed #2 as US and Canada", only Canada gets marked as final result.

      I will appreciate any help

        • 1. Re: Scripting
          philmodjunk

          In your script, you need to append the new value to the existing return separated list of values. There are several ways you can do this. Here's one:

          If [ IsEmpty ( FilterValues ( YourTable::Feld#2 ; "new value" ) ) ]
              Set Field [YourTable::Field#2 ; List (YourTable::Field#2 ; "new value") ]
          End If

          In place of "new value" you can put whatever calculation expression you need as long as both the If expression and the set field expression use the same calculation. (The If test is to check to see if the value has already been selected in Field#2.)

          • 2. Re: Scripting
            yomango

            Thank you for input. I will try it and let you know. Gracias, de nuevo

            • 3. Re: Scripting
              yomango

              Hi. Thank you for taking time to answer. Here goes my message again..

              Hi. Sorry to bother you. I did what you suggested when creating a script that takes an indication from a field and selecting on a second field (check boxes list value field) but it did not work. I do not know if you understood the question: I have two fields, field #1 is called "Country Regions" and it lists several regions as "US", "US& Canada", "South America",etc. The second field called "Countries" lists ALL the world countries with check boxes next to each country. I can have the script check mark ONLY ONE COUNTRY when I choose on of the regions, but if the region has more than one country, as in "US & Canada", the script only check marks the last country value I set on the script, not both countries (Check mark for US AND check mark for Canada). If I read you correctly, the script you suggested checks on the second field to see if it is empty, if not, it check marks it with the value.It does check mark ONE of the countries, not two or more countries as desired. And what if the second field is already check marked and I want to change the region, I think the script won´t work then. 
              Mainly, what I want to do is to have the script check mark two or more countries on the second field according to the region a choose on the first field.
              thank you again.

              • 4. Re: Scripting
                philmodjunk

                The script as written, takes a specified value of one check box, and if checked adds it to the check box values selected in another field without changing any existing selected values.

                If you have

                Africa
                US
                US & Canada

                In one list. And:

                Africa
                US
                Canada

                in another and you want a click on US & Canada to select the US value and the Canada value--overwriting any previous value selections in the second field, you could use this script:

                If [ Not IsEmpty ( FilterValues ( Table::Field1 ; "US & Canada" ) ) ]
                    Set Field [ Table::Field 2 ; "US¶Canada" ]
                End IF

                • 5. Re: Scripting
                  yomango

                  Great, great, great. It worked just as I wanted it. First time I use the "¶" operator. I do not even know what is it called though. Thank you very much.

                  • 6. Re: Scripting
                    philmodjunk

                    It's called the "Pilcrow" and in English it's a proof reader's symbol to start a new paragraph. In FileMaker, it's the symbol for a carriage return in calculated expressions such as these.

                    • 7. Re: Scripting
                      yomango

                      Hi, PhilModJunk. It's me again taking advantage of your generosity and your time. I have a question: is it possible to do a conditional formatting on a field so it fills in with a different color depending of what others fields show? I was able to make it turn ONE color only. But I need it to turn into 6 different colors. As I said, the condition comes from 6 different fields, not just one field changing its value. Thank you for taking your time to answer me.

                      • 8. Re: Scripting
                        philmodjunk

                        You can "stack" multiple conditional format expressions with each specifying a different fill color. If more than one expression evaluates to true, you'll see the last/bottom true expression's fill color applied.

                        • 9. Re: Scripting
                          yomango

                          Thank you for your time. I thought so. But since there are 6 conditioning fields, I do not know what color is the one that will show on top or if it will show as a "rainbow". Any way, I will try that and manage around it. Thank you again.

                          • 10. Re: Scripting
                            philmodjunk

                            The "top" and "bottom" I am referring to is the top to bottom order of conditional format expressions in the conditional formatting dialog. You can keep clicking the "Add" button to add as many "formulas" here as you need and specify a different color for each.

                            • 11. Re: Scripting
                              yomango

                              It worked! Thank you so much.