6 Replies Latest reply on Feb 12, 2010 8:41 AM by LaRetta_1

    Copy field value into another field

    millebjoerk

      Title

      Copy field value into another field

      Post

      HI!

      I am trying to make a script which should say:

      If (field A = "Yes")
      then field C copies the value of filed B
      End if
      If (field A = "No" or field A is empty)
      then field C takes the value 0
      End if

      My problem is making the "then" commands. what type of scriptcommand should I use? I've tried look up, replace, copy/paste and nothing works!
      I don't know where to place the script either. Can I add in one the fields A, B and C, when they already do have a value? It would be optimal if when I press "yes" in field A, that field C right after takes the value of field B. Should the script then be placed in field A? When I've tried to do that it seems as if i can't press "Yes" then.

      Hope somebody can help me, and ask if i'm not making sense or is clear in my discription.

      Regards, mille<!-- POLLS --><!-- FILES --><!-- SIGNATURE -->








        • 1. Re: Copy field value into another field
          mrvodka
            

          Why not just make FieldC a calculation field?

           

          Then the calc would just be: Case ( field A = "Yes"; FieldB; 0 )

           

          • 2. Re: Copy field value into another field
            ninja
              

            Howdy millebjoerk,

            Welcome to the Forum.

             

            Think whether or not you would be better served making FiledC a calculation field rather than running a script:

             

            FieldC =

            If (fieldA = "Yes" ; FieldB ; 0)

             

            If you are sure you want a script:


            millebjoerk wrote:
            If (field A = "Yes")
               SetField [ FieldC ; FieldB ]
            Else

              SetField [ FieldC ; 0 ]

            End if<!--    POLLS    --><!--    FILES    --><!--    SIGNATURE    -->


             

            your description was just fine... :)

             

            Edit: mrvodka beat me to it.  FYI, in this case "Case" and "If" pretty much do the same thing, choose your preference.


            • 3. Re: Copy field value into another field
              millebjoerk
                

              Thank you guys - That worked perfectly! Also thanks for replying so fast!

              • 4. Re: Copy field value into another field
                LaRetta_1
                  

                Ninja wrote:

                 

                If you are sure you want a script:


                millebjoerk wrote:
                If (field A = "Yes")
                   SetField [ FieldC ; FieldB ]
                Else

                  SetField [ FieldC ; 0 ]

                End if<!--      POLLS      --><!--      FILES      --><!--      SIGNATURE      -->


                Might field C need to be editabe?  Anyway, if I understand correctly, I would suggest that Case() be used EVEN if using script (and I'm not sure script would be necessary).  The script could then be shortened to:

                 

                Set Field [ field C ; Case ( field A = "Yes" ; FieldB ; 0 ]

                 

                ... no If/Else needed at all.  Many times, people use an If[] script step for a test when use Case() or If() as part of the Set Field [] does the trick and saves time. :smileyhappy:


                • 5. Re: Copy field value into another field
                  ninja
                    

                  A mighty fine point, LaRetta.

                   

                  I suppose it ends up at preference at some point, but I must say that your single line looks a whole lot cleaner.

                   

                  I find myself understanding other people's work more easily, or my own after a month has gone by, if the test is read before the result (If this is true, do this).  But your reversal (do this, If this is true) yields the correct result just as well.

                   

                  I find myself thinking about my Boss's attraction to reverse polish calculators while I prefer standard.  They both work fine.  Many times reverse polish is actually faster ... but not when I use it ;) .

                  • 6. Re: Copy field value into another field
                    LaRetta_1
                      

                    I first saw using single Set Field[] with Case() instead of If/Else by Ray Cologon (CobaltSky).  I stared at it in wonder for quite some time (it was when I was new to FM). 

                     

                    UPDATE:  It is especially nice when you have a multiple Case() statement.  :smileyvery-happy: