7 Replies Latest reply on May 20, 2014 8:13 AM by philmodjunk

    Using Set Field By Name in Find Mode with Variables

    Gale

      Title

      Using Set Field By Name in Find Mode with Variables

      Post

           My application needs a lot of complicated find scripts. There are so many different variations and requirements that it would be nice be as flexible as possible, and avoid all of the repetition involved in setting up all of those different scripts. The concept outlined by six.fried.rice at the link http://sixfriedrice.com/wp/dynamic-finds-in-filemaker-10/
           describes exactly what I’d like to do. 
            
           Basically, a dictionary concept is used to pass pairs of field names and values to the script. The dictionary pairs are parsed in a loop and Set Field Value is used to put the value into the appropriate fields on the appropriate form used for searching.
            
           For lack of a better imagination, consider the following. 
            
           Cartype Colours Options
           Convertible,  Red,  AC
           2-door ,Blue, Hand-held fan
           4-door, Black, Heating
                        Grey, Blanket
            
           Along with this information are a lot of other related records. In this particular instance, users may want to search for red convertibles, 4-doors with AC, whatever combination suits their mood.
            
           Assuming the user is on the correct layout, here’s the basic script:
            
           SetVariable[$parms; Value:Get(ScriptParameter) //push search parms into script
           EnterFindMode[]
           Loop
             Set Variable[$fieldname; MyCustomFunctionforParsing($parm)] //get field name
             Set Variable[$fieldvalue; MyCustomFunctionforParsing($parm)] //get field value
             Set Field By Name [$fieldname; $fieldvalue]
             CustomFunctionforStrippingOutInfo[$parm] //removes the first field/value pair from the string
             Exit Loop If(IsEmpty($parm)]
           End Loop
           Perform Find[]
            
           I’ve stepped through this code and see the right things going on with respect to $fieldName, $fieldValue and $parm. When it comes to Set Field By Name though, it does not put the values in the fields as expected. Replacing it with SetField DOES work, but that’s not going to work for me. Any suggestions on what might be wrong here?
            

        • 1. Re: Using Set Field By Name in Find Mode with Variables
          philmodjunk

               The text in $FieldName has to include both a table occurrence name and a field name.

               Do you see text like this in $FieldName? YourTable::FieldName

               or are you just getting "FieldName"?

               The first works, the second does not.

               PS. I pass multiple values in a script parameter like this:

               List ( "value1" ; "value2" ; "value3"; "Value4" )

               or more specifically:

               list ( GetFieldName ( Table::Field1 ) ; Table::Field1 ; GetFieldName ( Table::Field2 ) ; Table::Field2 ) .... )

               Then I can extract my values without needing a custom function:

               GetValue ( Get ( ScriptParameter ) ; 1 )

               will return the text "Table::Field1" in the above example.

          • 2. Re: Using Set Field By Name in Find Mode with Variables
            Gale

                 Thank you very much for your help. Monday was a holiday here, so sorry for not responding sooner. I like the way you suggest for passing multiple parameters, and will give it a shot. Getting rid of unnecessary custom functions seems like a good idea.

                 I do see the fieldname in the script as TableName::FieldName through the script debugger. Bypassing all of the processing and simply hard-coding values into the call works. Why it did not occur to me to try that last Friday afternoon is beyond explaination. From this experiment I think the formatting of the string passed into Set Field By Value is off - placing quotation marks around the fieldname in Set Field By Value seems to have done the trick. 

                 Edited to add: All of the problems I had were actually outside the scope of this script and were a result of passing the parameters incorrectly into the script. Duh.

            • 3. Re: Using Set Field By Name in Find Mode with Variables
              philmodjunk

                   That works, but it's the same as just using Set Field instead of set field by name. It no longer uses the text for the table::field passed as a script parameter.

              • 4. Re: Using Set Field By Name in Find Mode with Variables
                Gale

                     I see what you mean. 

                • 5. Re: Using Set Field By Name in Find Mode with Variables
                  philmodjunk

                       I would take another look at the text you are extracting from the script parameter. If it is off by even one character, the set field by name step will fail. If it is including a non visible character such as a space or return as part of this field reference, it may not be immediately obvious in the data viewer that your custom function is extracting the the wrong text.

                       Ps. There's a reason why is used the function GetFieldName ( Table::Field ) instead of just "Table::Field" to pass that reference to the script in a parameter. Should I later change the name of the Table Occurrence or the field in Manage | Database, "table::field" will no longer be the correct data to pass to the script and it will fail, but GetFieldName ( Table::Field ) will automatically update to pass the new text to the script and the script continues to work.

                  • 6. Re: Using Set Field By Name in Find Mode with Variables
                    Gale

                         You are exactly right. I have implemented your parameter passing suggestion from your initial response. This has simplified everything and ensures the correct information is passed to the script. Everything is now working as it should. This script will make managing all of the many different find combinations a user can come up with much easier to handle, requiring little interference from me. Thank you for your advice and help.

                    • 7. Re: Using Set Field By Name in Find Mode with Variables
                      philmodjunk

                           One thing to be careful of: List ( value1, value2, value3 )

                           will omit null values. If you have Field1 = "A", Field2 is empty, Field 3 = "C"

                           Then List ( Field1 ; Field2; field3 )

                           Produces the list:

                           A
                           C

                           and this can result in the value form Field 3 being used as the second script parameter value instead of the third.