5 Replies Latest reply on May 31, 2011 4:25 PM by philmodjunk

    Simple Script Headache

    JamesBransom

      Title

      Simple Script Headache

      Post

      Hi again, can anyone tell me why the "else if" in this script isn't doing what I expect?  It's called OnObjectEnter and OnObjectExit and is passed the following parameter: People::Name_Last & "¶" & "<<Last Name>>" when a person record is being added or edited.  I'm doing this in combination with conditional formatting in lieu of field labels so the user knows what field is being entered.

      Apparently, the "Else if" condition is evaluating to false even when the field is empty (although the field is active and contains the cursor).  I've also tried:  Else if [ LeftValues ( Get ( ScriptParameter ); 1) = ""] and Else if [ not LeftValues ( Get ( ScriptParameter ); 1)].  The latter evaluates to true when People::Name_Last is empty but also when it contains text other than "<<Last Name>>" (which I assume would evaluate to true also if it got a stab at).  What am I missing?

      Oh yea, I forgot to mention that the field is auto entered with "<<Last Name>>".

      Screen_shot_2011-05-27_at_9.14.25_PM.png

        • 1. Re: Simple Script Headache
          JamesBransom

          Ok, so I fixed it but I don't understand it; maybe someone could explain?

          I wrapped LeftValues ( Get ( ScriptParameter ); 1) in the Code() function and got 13 so now the script works with:

          Else If [Code ( LeftValues (Get ( ScriptParameter); 1)) = 13 ].  Huh? Carraige Return?  How'd that get in there?

          • 2. Re: Simple Script Headache
            LaRetta_1

            "Oh yea, I forgot to mention that the field is auto entered with "<<Last Name>>"

            I originally addressed the issue of the Set Field [ ] missing the field name.  You had:

            Set Field [ RightValues ( Get ( ScriptParameter ) ; 1 ) ]

            and it should be

            Set Field [ People::Name_Last ; RightValues ( Get ( ScriptParameter ) ; 1 ) ]

            When using Set Field [], there are two requirements: Specify Target Field (where you select the field name) and Calculated Result (where you enter the formulae).  The Else If[] wasn't working at all because it wasn't doing anything.


            • 3. Re: Simple Script Headache
              JamesBransom

              Thank you LaRetta for you response(s)!

              "...and it should be

              Set Field [ People::Name_Last ; RightValues ( Get ( ScriptParameter ) ; 1 ) ]

              When using  Set Field [], there are two requirements: Specify Target Field (where  you select the field name) and Calculated Result (where you enter the  formulae).  The Else If[] wasn't working at all because it wasn't doing  anything."

              Actually, that doesn't appear to be true.  Originally, I had exactly what you suggest, with the Field Name hard-wired into the script.  But since I'm applying this to several fields on the layout, I wanted to generalize it so that it would work on any field.  I tried this by referring the script step to "Self", but FileMaker complained.  So I passed the contents of the field in a parameter through the "Optional parameter" field on the "Set triggers..." dialog.  Apparently, "Specify Target Field" is not a requirement of Set Field [] because the script is now working without it (it probably assumes the currently active field, the one calling the script).  The problem appears to have been that, when the field is empty, with the script parameter:  People::Name_Last & "¶" & "<<Last Name>>", Get (ScriptParameter) returns "¶" for the first parameter value.

              This brings me to the broader point of your original (now edited) post:

              "I wouldn't be doing what you are doing at all but let's set that aside (since that is how we learn) and look at the thing which jumps out at me:"

              This happens to be my very first database project ever (not to mention, the first time I've looked below the surface of a computer) and it's a doozy.  Anyway, suffice it to say that, by the time I realized that field labels are a good thing for data entry (you don't need'em in layout mode because they're in the field), I had already spent many hours at layout design; it was either go backwards and change the layout or go forward and see what I could learn.  As you say, it's all about learning at this point, although I hope to be able to use this thing when it's done. Sealed


              • 4. Re: Simple Script Headache
                JamesBransom

                An afterthought!  Could this script stay generalized, but set the "Specify Target Field" in Set Field by passing the Target Field in the parameter with "Evaluate()"?  If so, how should that look?

                • 5. Re: Simple Script Headache
                  philmodjunk

                  You can pass a field name in the parameter and then use Set Field by name to modify the value in the field and can use Get Field to "read" the contents of the field (say to use in a calculation).

                  A safe way to pass the field name is to use the getfieldName function: GetFieldName (table::field) in the parameter expression. That way, changing the name of the field in Manage | Database | Fields won't break your script as the parameter will continue to pass on the correct field name to the script. (And you can pass on multiple items in a single parameter and then extract each item separately inside your script.)