5 Replies Latest reply on Feb 5, 2009 8:32 AM by Orlando

    Scripting Puzzle - Set Next Serial Value confusion

    LightningAd

      Title

      Scripting Puzzle - Set Next Serial Value confusion

      Post

       

      Having finally worked out how to resolve a problem i have had in getting a serial number to reset to 001 upon reaching 999, i have found a problem that i cannot understand.

       

      I added some more script to the Set Next Serial Value example as shown in the filemaker pro help files

       so it now reads:

       

      Go to new record/request/page(last) 

      if [tvc::serial >=999]

      set next serial value [tvc::serial; tvc::serial=1]

      else

       set next serial value [tvc::serial; tvc::serial+1]

      end if

      new record/request

       

       

      this works in that when it encounters a serial on the previous page that is 999 or more it reverts to back 000 - and then begins to climb the numbers again from there.

       

      ...the only problem is that it goes back to zero when the script tells it to go back to restart from number 1 ?

       

       

      I posted this at the end of a previous thread where the solution was being sought...but due to the length and obscure subject title, I have renamed it and posted specifically for this one issue...apologies if you have read this twice.

       

      Adam 

        • 1. Re: Scripting Puzzle - Set Next Serial Value confusion
          Orlando
            

          Hi there Adam

           

          Saw your other post just now but though I would reply here.

           

          In what context are you running this script? And is the field a number or text field?

           

          The reason it is going to zero, if what you have written is the same as the script woudl be the calculation in your set next serial value 'tvc::serial=1' This will be zero as the serial does not equal 1.

           

          Simply make it

           

          set next serial value [ tvc::serial; 1 ] 
           

          Also you do not need the else, as you may find you jump a number when running the script, as the Auto Enter serial value will already add a 1.

           

          The script may need to be modified depending on when it is run so if you can give more detail on that I will be more than happy to go through it some more.

          • 2. Re: Scripting Puzzle - Set Next Serial Value confusion
            LightningAd
              

            Hi Orlando,

             

            so if i understand you - using tvc::serial=1   does not tell the script to make serial =1 ?

             

            I have just tried changing the script to using a semi-colon, but i cannot get the Scriptmaker to accept the change. It just keeps telling me it expects an operator where i have the semi-colon. 

             

            The serial field it relates to is a Number field. 

             

             

            I have the script setup so that whenever the New Record button is selected the new record is generated with part of the clock number already in place. Because occasionally jobs get made out of sequence, i want the ability to change the serial number to reflect this.

             

            I also have a copy button that will refer to the previous record and will transfer some of the other data that was entered. 

             

            thanks

            Adam 

            • 3. Re: Scripting Puzzle - Set Next Serial Value confusion
              Orlando
                

              No if in the Specify Calculation dialog for the Set Next Serial Value step you put in "using tvc::serial=1" then you will not set the serial value to 1. What it will do a calculation to check if using tvc::serial equals 1 or not, adn return the value in Boolean, 1 or 0, so you are getting zero because using tvc::serial does not equal 1.

               

              In the Specify Calculation dialog just type 1, no semi-colon or anything.

               

              With regards to how you run the script. If you are running this each time a record is created, do you need the Serial at all, could you not look at the last record and add 1, reverting to 001 when at 999? Worth a thought.

               

              Also you if statement 'if [tvc::serial >=999]' if this is run after the record is created it will reset the serial counter to 1 when the next serial would be "999" so you will have the sequence 997, 998, 1, 2 etc, skipping 999 altogether. 

              • 4. Re: Scripting Puzzle - Set Next Serial Value confusion
                LightningAd
                  

                Also you if statement 'if [tvc::serial >=999]' if this is run after the record is created it will reset the serial counter to 1 when the next serial would be "999" so you will have the sequence 997, 998, 1, 2 etc, skipping 999 altogether. 

                 Thats why i put the New Record step after all the other steps in the script. It seems to be working fine without jumps.
                 
                Just tried the solution you suggested - works a treat.  Thanks very much for all the help on this one.  
                 
                Adam

                 

                • 5. Re: Scripting Puzzle - Set Next Serial Value confusion
                  Orlando
                     No worries Adam, glad I could help.