3 Replies Latest reply on Mar 8, 2010 5:48 AM by ninja

    Inserting text in a field under "IF" conditions

    millebjoerk

      Title

      Inserting text in a field under "IF" conditions

      Post

      Hi

       

      I'm trying to make a script which inserts a certain text if a condition is fulfilled and inserts another certain text if another condition is fulfilled in a field.

       

      I have tried with the following script:

       

      If [Products:: Max > Products::Current number ≥ Products:: Max - 2]                      

           Insert Text [Select; Products::Status; "Few products left"]

      End If

      If [Products:: Max  ≤ Products::Current number ]

           Insert Text [Select; Products::Status; "Products sold out"]

      End If

       

      But it does not work. It's like nothing happens as if it is not activated..

       

      Can anyone help me?

       

      Best, Mille

        • 1. Re: Inserting text in a field under "IF" conditions
          raybaudi

          Hi

           

          there's no need of a script...

           

          Simply make the field Status a calculation field with calc:

           

          Case(
          Current number ≥ Max ; "Products sold out" ;
          Current number ≥ Max - 2 ; "Few products left"
          )

          • 2. Re: Inserting text in a field under "IF" conditions
            millebjoerk

            That worked perfectly..

             

            But just to understand why the script didn't work, can you tell why? Even though it is not as simple as using a calculation field, shouldn't it work anyway?

            • 3. Re: Inserting text in a field under "IF" conditions
              ninja

              Howdy millebjoerk,

               

              It likely didn't work since you had multiple comparisons in a single expression without a logical operator:

               


              millebjoerk wrote:

               

              If [Products:: Max > Products::Current number Products:: Max - 2]                        


               

              you would write this as:

               

              If [Products:: Max > Products::Current number AND Products::Current number ≥ Products:: Max - 2]  

               

              My guess is that the "Products sold out" insertion worked right, but the "Few products left" didn't when you ran your script.  The "Products sold out" had only the single comparison.

               

              As raybaudi described and you've already done, the calculation field would be a better approach in this case.  The multiple comparison scripted "IF", however, can be part of your mental toolbox going forward.

               

              Edit: Fixed typo...