7 Replies Latest reply on Oct 14, 2015 2:04 PM by echosteve

    Is there a script or calculation to select a specific value from a value list?

    echosteve

      I am attempting to create an invoice that displays a service performed at a particular location.  Our company provides many service but we provide a particular service much more often then the others.  Currently when we create the invoice we would search by the date which would bring up all of the locations that were serviced that day and then using a value list we select the service we performed at each location.  We service many locations each day so it is time consuming to select a service for each location.  I would like to write a script or do a calculation that automatically assigns our most popular service to each location and then we can just make a few changes to account for our other services.  Is this possible using a script or calculation?

       

      Ticket Screen Shot.jpg

        • 1. Re: Is there a script or calculation to select a specific value from a value list?
          vavo

          Hi,

           

          I see two ways to do that:

          1. Use and auto enter value (or calc) defined for that field (In the field definitions)

          2. Use a script (trigger) to auto populate.

           

          In either case you can simply hardcode the value, i. e. enter "Fluid Level - Producing"

           

          or be more flexible, in case you edit the valuelist, and use functions:

           

          let ([

            listNumber = 1;           //change to the list you need

            valueNumber = 2;      // change to the position of the value you need

           

            vlist = getvalue (valuelistNames (get (filename));listNumber);

            value = getvalue (ValueListItems (get(Filename) ;vlist);valueNumber)

            ];

            value

          )

           

          Hope this helps,

           

          Valentin

          • 2. Re: Is there a script or calculation to select a specific value from a value list?
            echosteve

            Valentine,

             

            I have already started a script to create the ticket(invoice) to apply ticket numbers.  Can this be added to the script so when I create the ticket (invoice) it auto populates those fields.  If so how?

             

            2015-10-10_11-50-32.jpg

            • 3. Re: Is there a script or calculation to select a specific value from a value list?
              Extensitech

              I might rather recommend that you use an auto-entry calculation option on the field, with "do not replace" and "do not evaluate if" both unchecked.

               

              Case (

                   not IsEmpty ( self )

                   ; self

               

                   ; "the most likely value"

              )

               

              HTH

               

              Chris Cain

              Extensitech

              • 4. Re: Is there a script or calculation to select a specific value from a value list?
                vavo

                As Chris suggested, the best way is to use an auto enter calc. So it does not  need to go in your script, but rather in the field definition (manage database, double click your field). Check the "auto enter calculation" option and enter your preferred value or formula there. Now every time a record gets created that value will be put in your field.

                • 5. Re: Is there a script or calculation to select a specific value from a value list?
                  echosteve

                  I appreciate the input.  I am pretty week on my formula writing.  Could you please explain the formula is a little more detail.

                   

                  Thanks

                  • 6. Re: Is there a script or calculation to select a specific value from a value list?
                    Extensitech

                    In Manage Database, find the field and click on options. On the Auto-Entry tab, click "by calculation". Enter the formula I gave you, and uncheck the "do not evaluate..." option at the bottom of the window. Click OK. Uncheck the box that says "do not replace..."

                     

                    The function uses "case", "isempty" and "self". "Case" can be thought of as "in the case that..." and takes parameters for condition (something that's either true or false), result (what to return if the condition is true) and default (what to return if the condition is false). There are other options, but you can search help for them.

                     

                    Self, when used in a field definition, refers to the field you're defining.

                     

                    Isempty is either true or false, depending on whether the thing you're checking contains anything.

                     

                    So, the function says, essentially, "In the case that this here field is not empty, return whatever is in the field. Otherwise, return 'the most likely value'".

                     

                    Since we're allowing the calculation to enter a value even if the field is empty, or even if it has a value, then the field will always have something in it. When you first create the record, you'll get "most likely value". If you enter something, that'll be the "self" and it'll enter itself (basically, it'll keep whatever you put in). If you try to clear the field, it'll change to "most likely value".

                     

                    Does this help? I'm not sure which part's giving you trouble, so I probably explained stuff you already knew.

                     

                    Chris Cain

                    Extensitech

                    • 7. Re: Is there a script or calculation to select a specific value from a value list?
                      echosteve

                      Chris

                       

                      That is perfect feedback.  How would I set it up to select a specific value from a value list that automatically fill in that field?

                       

                      Thanks

                      Steve