1 2 Previous Next 17 Replies Latest reply on Oct 31, 2012 6:34 PM by cabarnes

    Numbering Sequence

    cabarnes

      Hpw can I create a series of numbers from an input of a number range?

       

      I have a "Beginning Ticket Number" and a "Ending Ticket Number" field (both numbers), and a "Number of Tickets Issuesd" field. The Number of Tickets field is calculated by Ending Ticket Number - Beginning Ticket Number + 1 to give the number of tickets.

       

      What I wouldlike to do is also have a record created for each ticket number automatically.

       

      For example if the beginning number was 501 and the ending was 514, z seprate record would be created with a ticket number of 501, 502, 503m etc.

       

      Reason is so that each ticketnumber can be searched by its own number.

       

      Any help o rpointing in tthe right direction would be greatly appreciated.

       

      Thanks,

      Craig

        • 1. Re: Numbering Sequence
          cortical

          use variables to parse the start and end numbers, and a loop script sequence to create the records. This uses the first record to enter the globals, but they could be in a different table...

           

          create_series

          #

          #JUST IN CASE - always include an allow abort if using a loop

          Allow User Abort [ On ]

          #

          Set Variable [ $_ex; Value:loop::g_start ]

          Set Variable [ $_to; Value:loop::g_end ]

          Set Variable [ $_n; Value:$_ex ]

          Set Field [ loop::number; $_n ]

          Loop

          New Record/Request

          Set Field [ loop::number; $_n ]

          Set Variable [ $_n; Value:$_n + 1 ]

          Exit Loop If [ $_n > $_to ]

          End Loop

          #

          #EXIT -  good coding always has an exit last step

          Exit Script [ ]

          • 2. Re: Numbering Sequence
            cabarnes

            Thanks for the reply, but I am a little confues on which fields in the table(s) to use. This is my table layout:

             

            Table - PassCon

            Fields - pass_end, pass_start

             

            Table - PassNumbers

            Fields - pass_numbers

             

            The starting & ending numbers would come from the pass_start & pass_end fields. I am guessing that the new rdcords would be in the PassNumbers table field pass_numbers. I guess that I am not clear on where to put the field names and where to run the script from.

             

            Thanks,

            Craig

            • 3. Re: Numbering Sequence
              cortical

              Normally, define globals in a separate Uitility table, but they can be anywhere, e.g. PassCon

               

              It sounds like PassCon table is really a 'batch' table. That was not apparant form your first post. Hence the use of the 2 globals to allow the user to enter the values.

               

              You create a record in PassCon to record the batch start and the batch end

              So the script button would be on the PasCon layout

              Alter the script to parse the $_ex (start) and $_to ( end) values from the PassCon::pass_start and PassCon::pass_end fields respectively

              The script then needs a go to layout PassNumbers AFTER the set variable $_to ( so it pulld the values while on the PassCon layout)  and BEFORE the set $_n a strta of the loop sequence

               

              You really need a check to prevent creating duplications , by clicking the button again at some point. A number of ways to approach this

              e.g. define a status field (number type) and have the script set the value = 1 after returning from the loop. Plus test for the value not equal 1 at the start of the script , and halt if fail the test

              e.g. or  rel based on the range..

               

               

               

               

               

              create_series

              #

              #JUST IN CASE - always include an allow abort if using a loop

              Allow User Abort [ On ]

              #

              Set Variable [ $_ex; Value:loop::g_start ]

              Set Variable [ $_to; Value:loop::g_end ]

              #

              GO LAYOUT passNumbers

              #

              Set Variable [ $_n; Value:$_ex ]

              Set Field [ loop::number; $_n ]

              Loop

              New Record/Request

              Set Field [ loop::number; $_n ]

              Set Variable [ $_n; Value:$_n + 1 ]

              Exit Loop If [ $_n > $_to ]

              End Loop

              #

              # return to PassCon

              GO LAYOUT original layout

              #

               


              #

              #EXIT -  good coding always has an exit last step

              Exit Script [ ]

              • 4. Re: Numbering Sequence
                cabarnes

                Thanks, but I seem totally lost by what you expalined. You mention $_ex (start) and $_to (end), then you mention the PassCon::pass_start and PassCon::pass_end fields in your explanation. In the script is

                Set Variable [ $_ex; Value:loop::g_start ]

                Set Variable [ $_to; Value:loop::g_end ]

                 

                Will g_start be PassCon::pass_start & g_end be PassCon::pass_end? Like the following?

                Set Variable [ $_ex; Value:loop::PassCon::pass_start ]

                Set Variable [ $_to; Value:loop::PassCon::pass_end ]

                 

                And were would the field PassNumbers::pass_numbers be placed?

                 

                Thanks for your help & patience. I am just starting to get into the variables.

                 

                Craig

                • 5. Re: Numbering Sequence
                  cortical

                  my fault ther Craig, copy/paste anomaly,

                   

                  you want to pull the values from the PassCon start/end fields ( which are not globals) into variables, so that once you have left the PasCon layout, and go to the PassNumbers table layout, you can use the variable values to calculate the PassNumber ( not that this is necessarily the best way to approach this -  creating  a batch of x, and letting a defined key in PassNumbers create the start/end numbers for the specified number of tickets would be preferable ). But as it stands it is a good enough exercise.

                   

                  Set Variable [ $_ex; Value: PassCon::pass_start ]

                  Set Variable [ $_to; Value:PassCon::pass_end ]

                   

                  Think of variables as a temporary scratch pad. Pull (parse) the source value into a variable(s); and as good practice, 'declare' the variables the script will use at teh start of the script ( even if the values ca't actually be parsed at that point [although one usually ignores this for counters like $_n])

                   

                  Parsing into a variable(s), allows you to cary the value(s) to another layout/table where the source value may not be directly accesible e.g. no relationship

                  If the source field was a global, then the value would be accessible form anywhere

                  variables are much like globals, but the ($)  local varable value only persists while the script is active

                   

                  try something like this:

                   

                   

                  #JUST IN CASE - always include an allow abort if using a loop

                  Allow User Abort [ On ]

                  #

                  # parse the start/end batch values BEFORE leaving the layout

                  Set Variable [ $_ex; Value:PassCon::::g_start ]

                  Set Variable [ $_to; Value:PassCon::g_end ]

                  #

                  GO LAYOUT passNumbers

                  #

                  # create the records for the sequence

                  Set Variable [ $_n; Value:$_ex ]

                  Loop

                  New Record/Request

                  Set Field [ PassNumber::number; $_n ]

                  Set Variable [ $_n; Value:$_n + 1 ]

                  Exit Loop If [ $_n > $_to ]

                  End Loop

                  #

                  # return to PassCon

                  GO LAYOUT original layout

                  #

                   


                  #

                  #EXIT -  good coding always has an exit last step

                  Exit Script [ ]

                  • 6. Re: Numbering Sequence
                    comment

                    cortical wrote:

                     

                    It sounds like PassCon table is really a 'batch' table.

                     

                    That's my impression too.

                     

                    cortical wrote:

                     

                    Hence the use of the 2 globals to allow the user to enter the values.

                     

                    Hence the start and end values are probably attributes of a batch and should not be global. Also, it seems likely that tickets should be related to the parent batch - as shown in the attached file.

                     

                     

                     

                    cortical wrote:

                     

                    #EXIT -  good coding always has an exit last step

                    Exit Script [ ]

                     

                    Why?

                    • 7. Re: Numbering Sequence
                      cortical

                      the globals were the initial suggestion to allow data entry, before it was apparent that a batch table existed.

                       

                       

                       

                      Why an exit? Standard best practice in a number of programming languages (Unix...) as I have always understood it.

                      • 8. Re: Numbering Sequence
                        comment

                        cortical wrote:

                         

                        Why an exit? Standard best practice in a number of programming languages (Unix...) as I have always understood it.

                         

                        Call me old-fashioned, but I need a reason.

                        • 9. Re: Numbering Sequence
                          cabarnes

                          Cortical - I tried the script how you have it, but it did not work.

                           

                          Michael - I looked at your file & script, but I don't really understand it.

                           

                          I've attached my file for reference.

                           

                          Thanks for your help.

                           

                          Craig

                          • 10. Re: Numbering Sequence
                            cortical

                            It only does exactly what you tell it to do; if you define the wrong names etc, that do not exist...

                             

                            create_series

                             

                            error 1 - parse from the fields you are entering data into; not the globals which are redundant given your batch table

                            Set Variable [ $_ex; Value:PassCon::g_start ]

                            Set Variable [ $#_to; Value:PassCon::g_end ]

                             

                            error 2 - set $_to = $_n, and not  $#_to

                             

                             

                            error 3 -  set the $_n = $_ex, and not "_ex"  ( which is a text value enclosed in quotes, and not a variable even if it wasn't.

                             

                             

                            error 4 - set the variable calculated result value to $_n,  and not the tagged field repetition

                             

                             

                             

                            script.png

                            • 11. Re: Numbering Sequence
                              cabarnes

                              Cortical - I made the changhes as shown below. It now creates one record with a quesion mark (?) in the _kp_passnumbers_id field. Please let me know what I am missing here.

                               

                              Thanks,

                              Craig

                               

                              #

                              #JUST IN CASE - always use an allow abort if using a loop

                              Allow User Abort [ On ]

                              #

                              #parse the start/end batch values BEFORE leaving the layout

                              Set Variable [ $_ex; Value:PassCon::pass_start ]

                              Set Variable [ $_n; Value:PassCon::pass_end ]

                              #

                              Go to Layout [ “PassNumbers” (PassNumbers) ]

                              #

                              #create the records for the sequence

                              Set Variable [ $_n; Value:$_ex ]

                              Loop

                              New Record/Request

                              Set Field [ PassNumbers::pass_numbers[$_n] ]

                              Set Variable [ $_n; Value:$_n + 1 ]

                              Exit Loop If [ $_n > $_to ]

                              End Loop

                              #

                              #return to PassCon

                              Go to Layout [ original layout ]

                              #

                              #

                              #EXIT - good coding always has an exit last step

                              Exit Script [ ]

                              • 12. Re: Numbering Sequence
                                cortical

                                I sent a corrected file, which works

                                 

                                You need to far more pedantic about the syntax; syntax is not forgiving.

                                 

                                 

                                Look at what you last sent; after set $_ex , set $_to, NOT $_n

                                 

                                and  then there is the set field Passnumbers step

                                 

                                here is the script from the corrected file I last apended. You need to correct you script to match what I sent.

                                 

                                 

                                Creat Series

                                #

                                #JUST IN CASE - always use an allow abort if using a loop

                                Allow User Abort [ On ]

                                #

                                #parse the start/end batch values BEFORE leaving the layout

                                Set Variable [ $_ex; Value:PassCon::pass_start ]

                                Set Variable [ $_to; Value:PassCon::pass_end ]

                                #

                                Go to Layout [ “PassNumbers” (PassNumbers) ]

                                #

                                #

                                create the records for the sequence

                                Set Variable [ $_n; Value:$_ex ]

                                Loop

                                New Record/Request

                                Set Field [ PassNumbers::pass_numbers; $_n ]

                                Set Variable [ $_n; Value:$_n + 1 ]

                                Exit Loop If [ $_n > $_to ]

                                End Loop

                                #

                                #return to PassCon

                                Go to Layout [ original layout ]

                                #

                                #

                                #EXIT - good coding always has an exit last step

                                Exit Script [ ]

                                • 13. Re: Numbering Sequence
                                  cabarnes

                                  Cortical - Thanks for your patience. This now works, and I see what I was doing wrong.

                                   

                                  One last thing, if you look at the database, on the layout PassDistribution, where the starting & ending numbers are put in, a pass type is selected. On the records that the script makes, I would like to also have the pass type be the same as on the entry page. For example, numbers 1-50 are a regular pass, so the layout would have the following entries:

                                   

                                  RECORD 1

                                  Pass Number: 1

                                  Type: Regular

                                   

                                  RECORD 2

                                  Pass Number: 2

                                  Type: Regular

                                   

                                  and for each record created.

                                   

                                  After New Record Request I added the following but it does not work (underlining added for emphasis):

                                   

                                  New Record/Request

                                  Set Field [ PassNumbers::pass_numbers; $_n ]

                                  Set Variable [ $_n; Value:$_n + 1 ]

                                  Set Field [ PassNumbers::pass_type; PassCon::pass_type ]

                                  Exit Loop If [ $_n > $_to ]

                                  End Loop

                                   

                                  and

                                   

                                  New Record/Request

                                  Set Field [ PassNumbers::pass_numbers; $_n ]

                                  Set Field [ PassNumbers::pass_type; PassCon::pass_type ]

                                  Set Variable [ $_n; Value:$_n + 1 ]

                                  Exit Loop If [ $_n > $_to ]

                                  End Loop

                                   

                                  Thanks,

                                  Craig

                                  • 14. Re: Numbering Sequence
                                    cortical

                                    it does not work because you do not have a valid relationship form PassNumber back to PassCon

                                     

                                    create a type_name field in PassNumbers

                                     

                                    declare a variable $_type at the start of the script, and parse the pass_type value to it, BEFORE leaving the PassCon layout

                                     

                                    then add a script step set field PassNumber::type_name =  $_type , inside the loop, i.e. so it hard codes the value to each new record

                                    1 2 Previous Next