7 Replies Latest reply on Apr 1, 2010 3:19 PM by philmodjunk

    using global variable as field name

    johnhorner

      Title

      using global variable as field name

      Post

      i am having a little trouble getting some global variables to cooperate.  here is the problem:

       

      i have a script which sets a global variable, $$PreviousFieldName, and this works correctly (as determined by looking at it's value with the script debigger/data window) and sets it's value to "Convention_1", for example.  now, after performing various other tasks, i want to set another variable which will give me the current contents of the previous field, "Convention_1" (as these contents may have changed since $$PreviousFieldName was set).

       

      i tried to use this expression:

       

      set variable [ $$CurrentFieldContents ; Value: $$PreviousFieldName ]

       

      but instead of giving me the contents of the field, it gives me the field name so that $$CurrentFieldContents = "Convention_1" and not the value contained in "Convention_1".  i  have also tried using this expression:

       

      set variable [ $$CurrentFieldContents ; Value: $$ActiveFieldTableName & "::" & $$PreviousFieldName ]

       

      but still no success.

       

      does anyone knnow how to do this correctly?  thanks.

        • 1. Re: using global variable as field name
          philmodjunk

          Use your variables with the GetField function.

          • 2. Re: using global variable as field name
            johnhorner

            thanks for the reply phil.  i re-wrote the set variable step to read:

             

            set variable [ $$CurrentFieldContents ; Value: GetField ( "$$PreviousFieldName" ) ]

             

            but for some reason it is still returning a "?" for the value of $$CurrentFiedContents even though i can see the contents of the field it is referencing and it is not a "?" or empty (it contains a simple text string, "Serial Number (Default)".

             

            any thoughts why this is still not working as expected?

            • 3. Re: using global variable as field name
              philmodjunk

              You'll need to include the appropriate table name , TableName::FieldName as the parameter to GetField. Keep in mind that all such script steps are "layout sensitive". That is the current record on the current layout's table occurrence can affect what value the function returns.

               

              Why not just store the value of the field in a variable so you don't have to deal with these complexities?

              • 4. Re: using global variable as field name
                johnhorner

                ok... i just tried the following:

                 

                set variable [ $$CurrentFieldContents ; Value: GetField ( "INVOICES::" & "$$ActiveFieldName" ) ]

                 

                which yields a "?" again, and i also tried:

                 

                set variable [ $$CurrentFieldContents ; Value: "INVOICES::" & GetField ( "$$ActiveFieldName" ) ]

                 

                which yields "INVOICE::?"

                 

                very perplexing.

                 

                to answer your question, the overall situation is rather complicated (at least for me).  i have 8 global fields with drop down menus that allow users to select a set of rules or components (e.g. date, year, client code, "_", ".", 4 digit serial number, 5 digit serial number, etc) which are used to create a user defined format for a serial number field which will essentially string together these 8 global fields (after determingin where in the string the serial number itself exists and incrementally increasing it).  i would like to constrain the user such that they can only specify a "serial number" type component in one of these 8 global fields.  so i have a script trigger to get the value and hte name of the field when it is entered and then another on modify script trigger to see if they are trying to set a second serial number and, if so, prevent them from doing so and reset the global field to the previous value.

                 

                so the problem is that as soon as i modify the global field by selecting a different value from the list, before there is any way to grab it's newly selected value, filemaker auto-tabs to the next field in the tab order and makes it the active field before the script advances to the next step (which triggers the on enter script in the next field, but i have a calculation to determine if this was the result of the user clicking in the field or this auto-tabbing behavior... so at least that is not a problem).

                 

                this is why i need to go back to the field i was originally in to get the new value and see if the user has selected a "serial number" related option, or one of the other options.

                 

                does that make any sense?

                 

                help?

                • 5. Re: using global variable as field name
                  philmodjunk

                  Is Invoice the table occurrence name in layout setup for your current layout when this script executes?

                   

                  Get Field ( "Table::Fieldname" ) is the correct format here.

                   

                  I don't think you need to do this though.

                   

                  "before there is any way to grab it's newly selected value, filemaker auto-tabs to the next field in the tab order and makes it the active field"

                  Have you tried using OnObjectExit to capture this value? That should work for you. You can even use the script trigger to pass the name of the field being exited to the script as a parameter if you need the field name, though the value should suffice here in your case.

                  • 6. Re: using global variable as field name
                    johnhorner

                    i am going to double check everything (table names, variable names, field names, etc) and try to figure out why this isn't working as it should.  i will also try your suggestion about using an onobjectexit script trigger.  great idea!  one question i have about that is that i noticed in the script trigger dialog box it says at the bottom of the window "if the script returns true, the original event will proceed normally, otherwise the event is cancelled."

                     

                    1.  what does it mean to "return true" (i know what it means for an "if" statement, but not a script)?  if i am just setting variables and fields within a script would that make it true or false?  after performing my intended actions is there a simple way to "return" a true or false value?

                     

                    2.  if it returns false, and the "event is cancelled", does that mean it will not auto-tab into the next field?  that would be useful...

                     

                     

                    • 7. Re: using global variable as field name
                      philmodjunk

                      Exit Script [ Result: False ]

                       

                      Is how you would set a return value of false.

                       

                      This can be a very useful feature. For OnObjectExit, it leaves the cursor in the field. This only works for certain triggers. You can look this up by searching "setting up script triggers" in the filemaker help system.