8 Replies Latest reply on Jul 12, 2016 1:30 PM by clogan

    Troubleshooting a Script

    clogan

      Hello,

      So my boss asked me to troubleshoot an old script that was built many years ago by someone other than me. This script is to create a new Job Number for a new job in our job database. It is supposed to start at .100 at the beginning of every year, and then increase by .001 every new job that is created. The problem is, whenever it creates a number that is a multiple of 10 (.150, .370, .400, etc) it will drop the 0s at the end of the number, and show up in the database as (.15, .37, .4, etc) instead of the hundred value it's supposed to be. I've done a little troubleshooting and haven't found anything outside of the script language that could be a problem. All of the fields mentioned are text or number fields. Can anyone tell me why it is doing this, and help me to fix whatever is causing it? Please let me know! The script is as follows.

       

      Go to Layout [ "Weekly Report" (Jobs Database) ]

      Show All Records

      Sort Records [ Restore ; No dialog ]

      Go to Record/Request/Page [ Last ]

      Set Variable [$Trans ; Value: Jobs Database: :Transition Number ]

      Show Custom Dialog [ "In the next screen, enter Department" ]

      Enter Find Mode [ Pause ]

      Perform Find [ ]

      Sort Records [ Restore ; No dialog ]

      Go to Record/Request/Page [ Last ]

      Duplicate Record/Request

      If [$Trans < Year ( Jobs Database: :Creation Date ) ]

           Insert Calculated Result [Select ; Jobs Database: :Transition Number ; Year ( Jobs Database: :Creation Date ) & ".100" ]

      Else If [$Trans >= Year ( Jobs Database: :Creation Date) ]

           Insert Calculated Result [Select ; Jobs Database: :Transition Number ; $Trans + .001 ]

      End If

      Go to Field [ Jobs Database: :Job Number ]

      Insert Calculated Result [Select ; Jobs Database: :Transition Number & "." & Jobs Database: :Department Code ]

      Clear [ Select ; Jobs Database: :Done ]

      Go to Layout [ "Project Record" (Jobs Database) ]

      Perform Script [ "Make Schedule" ]

        • 1. Re: Troubleshooting a Script
          David Moyer

          I believe that this is just a formatting issue.  In Layout mode, set a fixed number of digits to display for that field (Transition Number).  It's in the Inspector:  Data tab - Data Formatting - Format "Decimal".

          • 2. Re: Troubleshooting a Script
            clogan

            Thank you for your quick response! However, I don't think this is the issue. When I access the inspector for the job number field, the tab is greyed out and says "No options available."

            The end result for an entry in the job number field should look something like "2016.123.ABC" but when a multiple of ten, it will look like "2016.12.ABC" and has to be manually changed.

            • 3. Re: Troubleshooting a Script
              David Moyer

              The "job number" appears to be a calculation, a concatenation that includes the Transition Number in the middle.  That calculation should looks something like:

              Job Year & "." &

              GetAsText(Int(Transition Number * 1000)) & "." &

              "ABC"

              1 of 1 people found this helpful
              • 4. Re: Troubleshooting a Script
                ron.harris

                Nice answer. 

                 

                This answer satisfies when the transition number reaches .200 (truncates to .2).

                1 of 1 people found this helpful
                • 5. Re: Troubleshooting a Script
                  David Moyer

                  Sorry dude,  how about this:

                  Job Year & "." &

                  Right ("000" & GetAsText ( Int ( Transition Number * 1000 ) ); 3) & "." &

                  "ABC"

                   

                  ... that should handle .001 and .1

                  • 6. Re: Troubleshooting a Script
                    clogan

                    Ah! This does make a lot of sense and is definitely on the right track!!
                    The problem now is that the calculated result input into the Job Number field does not include the Year- the Year somehow inputs automatically through something else in the script. So when i attempted to replace the original calculation for the job number field with your calculation, it ended up looking like 2016.2016236.ABC. When I then took the year and the first "." out of the equation, the whole middle string of numbers disappeared, leaving me with 2016.ABC. I attempted a few other solutions: turning the IF statement values from decimals to whole numbers and deleting the * 1000 in the calculation (outcome: 2016236.ABC - attempt to add a "." to split the year from number and it turned out .2016236.ABC instead.) What do you think?

                    • 7. Re: Troubleshooting a Script
                      David Moyer

                      Sorry - this is difficult to answer without knowing if Transition Number is a text field or a number field.

                       

                      Can you check that for me, please?

                      • 8. Re: Troubleshooting a Script
                        clogan

                        This worked! Thank you so much!