1 2 Previous Next 18 Replies Latest reply on May 5, 2011 11:52 AM by margotjacqz

    script with variable table name and fixed field name

    margotjacqz

      Title

      script with variable table name and fixed field name

      Post

      What i want to do is easy in separate hard coded scripts, but am trying to understand if it can be done in one, to allow for additional tables etc.

      Tables: People, Company, Projects, ToDo. Each has a field FindSelect which is a check box for short term use in reviw and subsorting. After a Find, I may review the found set and check FindSelect to create a new individualized subset which might be used for any number of things.  In one session this might happen several times for different projects. I have a button that will clear all checked boxes in the active category only- That is I'd prefer not to clear checkboxes globally.

      GetAllRecords and SetField [tablename::FindSelect; value:" " ] 

      But of course I have to specify the tablename and therefore have either multiple scripts or one with many IFs.  

      So, my question: Wondering how to pass a variable table name into the SetField statement.

      Have found that Get(ActiveFieldTableName)::FindSelect does not work, but it really ought to. <s> And, no certainty on what will be the active field of course. There is something else I am sure, based on context I expect, but it's too subtle for me.

        • 1. Re: script with variable table name and fixed field name
          philmodjunk

          Try using SetFieldByName

          You can use an expression such as Get ( ActiveFieldTableName ) & "::FindSelect"

          as the first parameter of SetFieldByName.

          Since that "hardwires" your script to a field name and a future change to the field's name could break it, I do the following when possible:

          Pass a parameter to the script with this expression as the parameter: GetFieldName ( People::FindSelect )

          You select the field that is appropriate for each button and script trigger that you use to perform your script.

          Then SetFieldByName can refer to Get ( ScripParameter )

          What makes this really nice is that if you rename the field and/or the table occurrence, the name passed to the script updates to match and your script doesn't break.

          • 2. Re: script with variable table name and fixed field name
            margotjacqz

            Bingo!!  It was the AMPERSAND and QUOTES I was missing.  I haven't quite mastered the textural grammer obviously. 

            But the second options is even more elegant, and the way I like to think. I hadn't realized that the scriptparameter could do that.

            • 3. Re: script with variable table name and fixed field name
              philmodjunk

              Evaluated script parameters can be very useful. In one of my scripts, the script deletes a clicked portal row after first highlighting the row and then displaying text from the clicked portal row in a custom dialog in order to confirm the delete. Since all the table and layout specific references are evaluated in the script parameter, I can import this script error free into any file where I want to add a button to the portal row to delete it.

              • 4. Re: script with variable table name and fixed field name
                margotjacqz

                Umm .. I am still missing something.

                 #set script parameter (activetable)::FindSelect
                Go to Layout [ original layout ]
                Show All Records
                Set Field By Name [ "Get ( ScriptParameter )"; "" ]  /tried with and without quotes/

                Is having no effect. Did I mention this is a checkbox field, with a single value.

                previous hardcoded effort used Replace Field Contents (table::FindSelect; ""). brought up a confirmation dialogue and then cleared the x's on yes.  So there is something I am not understanding about set field? or a checkbox? or punctuation ...  I am feeling pretty dull right about now.

                • 5. Re: script with variable table name and fixed field name
                  philmodjunk

                  Why not use getfieldname ( yourtableoccurrencename::yourfieldname ) ?

                  Expressions in the script parameter evaluate just like any other calculation, if you want to use your method, you still need those quotes and an ampersand to concatenate the two.

                  One you have the correct text passed as the script parameter, you can use Get ( ScriptParameter ) without the quotes.

                  Basic rule for quotes is that you enclose data in quotes if you want that exact text, not the contents of the field or variable you've named. If you don't use quotes, filemaker expects variables, field names, functions and other key words.

                  • 6. Re: script with variable table name and fixed field name
                    margotjacqz

                    MY bad typo  I do have   GetFieldName( activetable::FindSelect).

                    yet, the set field is not setting it as "".

                    • 7. Re: script with variable table name and fixed field name
                      philmodjunk

                      I've used this method in a number of cases, so I know it works.

                      Can't see any reason from what you've posted why it doesn't. Do you have FileMaker advanced? If so enable the script debugger and data viewer and run your script to see what's happening and so you can check to see exactly what is being passed as the script parameter.

                      If not, you could add a Show custom Dialog [Get ( ScriptParameter)] step to the beginning of your script and then run it to double check to see what data is actually being passed as the parameter.

                      • 8. Re: script with variable table name and fixed field name
                        margotjacqz

                        No advanced, so tried the dialogue. The ScriptParamter is correct (PeopleContactAll::FindSelect).

                        Suggests there is something in the field set up? or an error check? or something else I haven't recognized. As mentioned, previous version ended with: 

                        Replace Field Contents ((PeopleContactAll::FindSelect);""). This brought up a dialogue to confirm, but the defualt of course is no change.

                        • 9. Re: script with variable table name and fixed field name
                          philmodjunk

                          Are you on the correct layout when this script runs? (Just thought of that one).

                          If you are on the layout for one of the other table occurrences, the reference to the field may not change any field or it may change the field of a different record. And a layout based on People and a layout based on PeopleContactAll, even if these are table occurrences of the same data source table, can result in different records or no record being modified.

                          • 10. Re: script with variable table name and fixed field name
                            margotjacqz

                            Sorry, My layout is  Table: PeopleContactAll.

                            • 11. Re: script with variable table name and fixed field name
                              philmodjunk

                              The ScriptParameter is correct (PeopleContactAll::FindSelect).

                              Does the script parameter include the parenthesis?

                              Don't need those and they might be why this isn't working for you.

                              • 12. Re: script with variable table name and fixed field name
                                margotjacqz

                                Um, sorry, no parentheses.  Inclined to just put this aside for now and it will leap out some day.or if I just keep talking about the details ...

                                I am convinced there is some difference in ReplaceFieldContent and SetFieldValue in delaing with this checkbox set up: One item in value list, "check".

                                • 13. Re: script with variable table name and fixed field name
                                  philmodjunk

                                  This should be used in neither Replace Field Contents nor in Set Field. Neither of those can refer to a field indirectly in this fashion.

                                  It can only be used in Set Field By Name.

                                  • 14. Re: script with variable table name and fixed field name
                                    margotjacqz

                                    Phil, Yes. I was shortcutting to the differences. Allow me the full summary of the situation as I understand it at the moment. A Field, appropriate to various categories: FieldSelect. It is included in layouts as a checkbox. The goals: a button that will clear all instances of checked boxes in the current category.  Two alternative scripts, hardcoded and universal, set up on the same button: examples below. 1. works as expected. 2 does not.

                                    1.
                                    Go to Layout [ original layout ]
                                    Show All Records
                                    Replace Field Contents [ PeopleContactAll::FindSelect; "" ]

                                    2.  #set script parameter GetFieldName (activetable)::FindSelect
                                    Go to Layout [ original layout ]
                                    Show All Records
                                    Set Field By Name [ Get ( ScriptParameter ); "" ]

                                    1 2 Previous Next