1 Reply Latest reply on Jul 13, 2017 9:29 AM by philmodjunk

    odd behavior with if statement inside a replace


      I had the following replace function inside a replace function running in a script ...


      If( IsEmpty( table::field ); $variable )


      and it was leaving a bunch of the found set empty.  So even though the value was empty (I can click in it and confirm there is no blank spaces or anything), it was not entering the variable value.


      If I used this function inside the replace function instead ...


      If( IsEmpty( table::field ); $variable ; table::field )


      then it works fine.  All the found set gets replaced.  But ideally I don't want to use this second function, since I didn't want to alter the field (forcing a reindex) if no change was needed.


      What's odd about this is that (I think) it worked fine for months, then suddenly this week it seems to be not working.  I have tried repairing the database just in case something was damaged, but no difference in the functionality.


      Is the 1st function not valid?  I always thought it was ok to have an if statement without a corresponding else, but maybe not?



        • 1. Re: odd behavior with if statement inside a replace

          Don't see how the original expression could ever work for what you want.


          If( IsEmpty( table::field ); $variable )


          will return a null result if the field is not empty and that null value will then clear the field.


          If you don't want to modify the field if there's data in it, perform a find that omits those records before doing the replace and they won't be modified.


          You can do a find with just an = in the field if you want to find all records where the field is empty.