1 2 Previous Next 23 Replies Latest reply on Jun 25, 2017 6:09 AM by Abingdon

    not IsEmpty

    tays01s

      I want to set certain fields if they are empty:

      Commit Records/Requests

      If [ not IsEmpty ( Home::Firstname and Home::Lastname )]

      Exit Script [ ]

      Else

      I then set the fields

      End If

       

       

      The setting of the fields works fine; I've tested it minus the 'If/ Exit/ Else/End If'. I've also tried the alternative approach of 'IsEmpty' combined with field1 or field2. Any ideas why the above fails?

        • 1. Re: not IsEmpty
          Devon Braun

          problem here: if(not isempty(field1 and field2))

           

          try this: if(not isempty(field1) and not isempty(field2))

           

          or this: if(field1 & field2<>"")

          • 2. Re: not IsEmpty
            Stephen Huston

            What is your actual script step(s) to set the fields. You didn't give that info though that appears to be what's failing.

            • 3. Re: not IsEmpty
              bigtom

              (not IsEmpty ( Home::Firstname)) and  ((not IsEmpty ( Home::Lastname )) . This has always worked better for me. This is conditional on both names being Filled already.

              • 4. Re: not IsEmpty
                Devon Braun

                Side question:

                Any down-sides/up-sides -- performance or otherwise -- to using isempty(field) vs field=""

                • 5. Re: not IsEmpty
                  CarlSchwarz

                  tays01s wrote:

                  Home::Firstname and Home::Lastname

                  the "and" operator will always return 1 or 0

                  isempty ( x and x ) will never be true because '0' is not empty.

                  • 6. Re: not IsEmpty
                    bigtom

                    I have had IsEmpty ($var) not work properly, but $var="" always works. Anyone have an idea on this with variables?

                    • 7. Re: not IsEmpty
                      CarlSchwarz

                      bigtom wrote:

                       

                      I have had IsEmpty ($var) not work properly, but $var="" always works. Anyone have an idea on this with variables?

                      Does isempty( trim( $var )) work?

                      Perhaps there is a special character in the variable.  Back many versions ago I had to use trim() to get a truly empty field, I haven't noticed that being the case lately though...

                      1 of 1 people found this helpful
                      • 8. Re: not IsEmpty
                        tays01s

                        Stephen: No, I've checked the Set Field steps in isolation; they definitely work.

                         

                        Big Tom: I had used ="" but didn't get the whole lot to work, but this does:

                         

                        Home::Firstname  ≠ "" and

                        Home::Lastname  ≠ ""

                         

                        So the script correctly exits if all fields are filled, 'Else' it Sets all fields. Of course for some peoples purposes they'd want to individually check fields and 'Set Field' only if that particular field is empty. For my purpose I need to ponder which is best. BTW, the script is a little slow to Set Fields; not sure why.

                        • 9. Re: not IsEmpty
                          beverly

                          FYI, for those following:

                          • the "&" is text concatenation
                          • the "and" is a boolean test
                          • IsEmpty() returns a boolean (true/false) as 1/0
                          • "Not" reverses the results

                          I made a chart to show different variations:

                          A_n_B.jpg

                          Throw in OR and you get different results, for example:

                          Not IsEmpty(A) OR Not IsEmpty(B)

                          It can all be confusing, so I might work from the positive side:

                          If [ IsEmpty(A) OR IsEmpty(B) // both must be complete ]

                               do this

                          Else

                               do that

                          End If

                          Beverly

                          2 of 2 people found this helpful
                          • 10. Re: not IsEmpty
                            siplus

                            when you have a problem, it's important to describe it in plain terms, without using filemaker notation.

                             

                            Like:

                             

                            I have 2 fields, firstName and lastName. E means empty, F means filled.

                             

                            fn          ln

                            E          E          I want A to happen

                            E          F          I want B to happen

                            F          E          I want C to happen

                            F          F          I want D to happen

                             

                            just tell us what A, B, C and D are, and let us coin the shortest formula that will achieve your goal.

                             

                            Hint: it might be that we won't be using IsEmpty()...

                            1 of 1 people found this helpful
                            • 11. Re: not IsEmpty
                              William-Porter

                              bigtom wrote:

                               

                              I have had IsEmpty ($var) not work properly, but $var="" always works. Anyone have an idea on this with variables?

                               

                              Hmm. I don't think IsEmpty() has ever failed me with a variable (or anything else). Of course IS empty is different from LOOKS empty. As Carl S. points out, you could have a space or a return or something in there.

                               

                              I vaguely recall that when IsEmpty() was added to our toolkit, we were encouraged to use IsEmpty() rather than ="" as the former was going to be more reliable. I don't know if that's actually true.

                              • 12. Re: not IsEmpty
                                William-Porter

                                CarlSchwarz wrote:

                                 

                                bigtom wrote:

                                 

                                I have had IsEmpty ($var) not work properly, but $var="" always works. Anyone have an idea on this with variables?

                                Does isempty( trim( $var )) work?

                                Perhaps there is a special character in the variable. Back many versions ago I had to use trim() to get a truly empty field, I haven't noticed that being the case lately though...

                                 

                                Using "Trim" will only work to get rid of spaces. If $var has a return character in it, IsEmpty(Trim($var)) is going to return 0 (not empty).

                                • 13. Re: not IsEmpty
                                  siplus

                                  Here's a test that, at least on my machine, suggests that Length() is slightly faster that IsEmpty.

                                  ( On weekends each picks his fun, sometimes mine is to build a benchmark   )

                                   

                                  YMMW. (Both on the results and on the fun factor)

                                   

                                  I suggest to hit "Restart", decide the # of iterations (10k - 50k) then hit "Run test" 3 - 4 times after each run (which does 10 cycles each)

                                  • 14. Re: not IsEmpty
                                    SteveMartino

                                    Pretty cool.  For me, FMP 16 and Windows 7, trying it as you suggest and multiple ways/times, IsEmpty was always about 10% faster.

                                    1 2 Previous Next