13 Replies Latest reply on May 25, 2011 9:06 AM by philmodjunk

    How Do You Reference An Unknown Field

    TedN

      Title

      How Do You Reference An Unknown Field

      Post

      What script is used to reference a button that is clicked so that the button can be used in script?

      If one of many buttons is clicked, how do you refer to that button in FileMaker script, i.e what is the equivalent of the VB term Selection?

        • 1. Re: How Do You Reference An Unknown Field
          LaRetta_1

          You use Script Parameter.  When you attach a script to a button, you can insert a different value (for each button) into the Optional Script Parameter and use it in the same script.  Example ... Three buttons attached to same script named Update.  Each button holds a different script parameter of 1, 2 or 3.

          Update script:

          Set Field [ anyField ; Get ( ScriptParameter ) ]

          However, you haven't provided enough information to know what you are really looking for, Ted, so if this isn't what you want, please explain more. :^)

          • 2. Re: How Do You Reference An Unknown Field
            TedN

            Thanks for your reply LaRetta.

            So I looked up ScriptParameters and it seems to be the way to go. I can't quite work it out though. The following is a simplified explanation of what I want to do.

            Let's say I have two buttons, ButtonA and ButtonB. I want each of the buttons to call on the same script. The script modifies only the clicked button so I need to tell the script what button has been clicked.

            That's the nub of the problem. How do I do that.

            I've tried putting the button name in the scriptparameter but I couldn't get it to work.

            Thanks for your help.

            • 3. Re: How Do You Reference An Unknown Field
              philmodjunk

              How are you trying to "modify the button"? You can't directly modify any button with a script, but there may be ways to produce the same result if you let us know what kind of change the user should see when they click the button.

              • 4. Re: How Do You Reference An Unknown Field
                aammondd

                Wont setting a Global Field with an input value and then use the OnObjectModify script trigger work as well?

                • 5. Re: How Do You Reference An Unknown Field
                  philmodjunk

                  Yes, if it's what the user wants to see on their layout. The "look and feel" can be slightly different.

                  • 6. Re: How Do You Reference An Unknown Field
                    LaRetta_1

                    Well, you can name the text on a button to <<$$button>> and then script:

                    Set Variable [ $$button ; Get ( ScriptParameter ) ]
                    Freeze Window

                    ... but again, we are missing what you want to do, Ted.  Can you please be specific?  If you want to turn a field into a button, and tell FM to grab that field name so you can perform a Set Field By Name[] then we can do that as well.  If you want to know which button was clicked, you can put that value within it's script parameter as I explained originally and then the script refers to THAT parameter.

                    So we clearly need more specific description of what you are doing ... step by step please ... describe the User experience and what should happen. :^)

                    • 7. Re: How Do You Reference An Unknown Field
                      TedN

                      LaRetta,

                      I want to change the image on the button that has been clicked. The following script changes the image on TickButton depending on the existing image. But I need to put a "variable" in place of TickButton so the script can apply to any clicked button.

                      If [ButtonImage::TickButton = ButtonImage::BlankContainer]

                          Set Field[ButtonImage::TickButton::ButtonImage::TickContainer]

                      Else

                          Set Field[ButtonImage::TickButton::ButtonImage::BlankContainer]

                      End If

                      I know there's neater ways of doing this (Phil showed me one) but at my level of understanding of databases the above script is more in my comfort level.

                      Thanks,

                      • 8. Re: How Do You Reference An Unknown Field
                        philmodjunk

                        Here's a trick that will serve the immediate need:

                        Your "buttons" are of course, container fields.

                        In layout mode, click your first container field, select Button setup...., select Perform Script and enter this expression as the script parameter:

                        GetFieldName ( YourTable::ContainerFieldButton1 )

                        Do the same for the second container field, but use: GetFieldName ( YourTable::ContainerFieldButton2 )

                        Now your script can be written as:

                        Set Variable [$FieldName ; value: Get ( ScriptParameter ) ]

                        If [ getField ( $FieldName ) = ButtonImage::BlankContainer ]
                           Set Field By Name [ $FieldName ; ButtonImage::TickContainer ]
                        Else
                           Set Field By Name [ $FieldName ; ButtonImage::BlankContainer ]
                        End If.

                        Using GetFieldName to pass the table and field name as a parameter is a trick that keeps your script working correctly even if you later use Manage | database to rename the field or the table occurrence to be something different.

                        • 9. Re: How Do You Reference An Unknown Field
                          TedN

                          That worked perfectly. Thanks all.

                          • 10. Re: How Do You Reference An Unknown Field
                            TedN

                            One small problem. I've created a new table (ImageTable) and placed the Tick and Blank fields there. I've changed the script to reflect this but now the images don't alternate on the buttons, i.e. nothing happens.

                            The revised script is:

                            Set Variable [$varTemp ; value: Get ( ScriptParameter ) ]

                            If [ getField ( $varTemp) = ImageTable::Blank ]
                               Set Field By Name [ $varTemp; ImageTable::Tick ]
                            Else
                               Set Field By Name [ $varTemp; ImageTable::Blank ]
                            End If.

                             

                            The script that works, when I refer to the images in the same table is:

                            Set Variable [$varTemp ; value: Get ( ScriptParameter ) ]

                            If [ getField ( $varTemp) = DataInput::Blank ]
                               Set Field By Name [ $varTemp; DataInput::Tick ]
                            Else
                               Set Field By Name [ $varTemp; DataInput::Blank ]
                            End If.

                             

                            What am I doing wrong?

                            • 11. Re: How Do You Reference An Unknown Field
                              philmodjunk

                              Since you've added a new table, did you also define a relationship linking it to the table occurrence of the layout where you have these buttons?

                              • 12. Re: How Do You Reference An Unknown Field
                                TedN

                                Yes, that was the problem. It works OK now.

                                However, the only reason I created the second table was because I didn't want the image containers to appear in my main table layout. I now realize that you can remove a field from the layout but still refer to it as it is still in the table. Voila!

                                So, I've removed the image table completely and removed the image fields from the layout, revised my script and everything's cool.

                                I think I've progressed from total confusion to a foggy understanding.

                                One small thing. How do you copy script so it can be pasted into, say the forum. I can select all the script and copy it, but it doesn't get copied to my clipboard to allow me to paste it elsewhere.

                                • 13. Re: How Do You Reference An Unknown Field
                                  philmodjunk

                                  It would be nice if the script editor were text based. Many have requested that feature: http://www.filemaker.com/company/feature_request.html

                                  In the meantime:

                                  1. You can upload a screen shot by clicking the edit link to your original message and uploading it there
                                  2. You can upload a screen shot to a file share site and post the download link to a new response you post here.
                                  3. You can print a script to a PDF, open the PDF and then select and copy the script as text from the opened PDF.
                                  4. If You have FileMaker advanced, you can generate a database design report and copy the script as text from there.