4 Replies Latest reply on Feb 24, 2014 1:31 AM by ziceg

    Autoenter calculation help

    ziceg

      Hi

       

      I'm trying to get an autoenter calculation to happen on a couple of fields when a particular event happens, but not having much joy.

       

      I have a field called Received where it has a checkbox/radial button that when it get's checked as "yes" (only option) I need it to then enter information in a couple of other fields:

      - Received by (Account Name) of person who checked that "Yes" in Received

      - Receive on (Timestamp) on when that person checked that "Yes" in Received.

       

      I have tried to put a script trigger (both OnObjectExit and OnObjectModify) on the Received field in the data entry layout but did not work, most problably issue was in script attached to it, but not sure where I wen't wrong.

       

      Script =

      Insert Calculated Result [Select; Production::Received by; Get ( AccountName)]

      Insert Calculated Result [Select; Production::Received by; Get ( CurrentTimeStamp)]

       

      Hope someone can help me. Many thanks in advance

        • 1. Re: Autoenter calculation help
          PalmDBS

          One possibility is that the field is not on the layout (a requirement of Insert Calculated Result).  Why not just use Set Field?  That won't require the field be on the layout.

           

          Also, OnObjectModify is not generally a good place to do something like this.  In a checkbox, it happens to not matter as much, but in a text field it would trigger on every keystroke, so I would get into the habit of OnObjectSave.

           

          Also make sure you account for (or block) somebody unchecking the box.  If allowed, and you want to then clear those fields, you can do an If/Then/Else on the checkbox value to either set or clear the field values.

          • 2. Re: Autoenter calculation help
            ziceg

            That helped heaps, it's now working .  Now I just need to figure out how to include the scripting for the if/then/else you mentioned to stop them or at least make them think before they untick the checkbox

            • 3. Re: Autoenter calculation help
              PalmDBS

              Something to the effect of:

               

              If[Production::Received = "Yes"] Then

                Set Field[Production::Received by; Get ( AccountName)]

                Set Field[Select; Production::Received by; Get ( CurrentTimeStamp)]

              Else

                Show Custom Dialog["Are you sure you want to UNMARK this item as received and clear the Name/Timestamp?"]

                // Assuming Button 1 is yes

                If[Get(LastMessageChoice)=1]

                  Set Field[Production::Received by; ""]

                  Set Field[Select; Production::Received by; ""]

                Else

                  #reset the Received field back to Yes

                  Set[Production::Received = "Yes"]

                End If

              End If

               

              Now, you could alternatively do your safety check in an onobjectvalidate trigger, and nullify the change from "Yes" to "" before it actually takes place.  THat method is porbably a more correct way to do it, but I tend to try to group/combine my triggered scripts so I can do as much with one trigger as possible, leaving the other trigger space open for a completely different script if I need.

               

              Mike

              • 4. Re: Autoenter calculation help
                ziceg

                Thank you so very much for your helps, it's now all working a treat!