9 Replies Latest reply on Jul 4, 2017 3:00 AM by tom.seager

    Keep leading zeroes in a calculated numerical string in a text field


      Hi there,


      I have recently been developing digital pdfs for salespeople to use to process orders. These are very nearly complete.


      One aspect of them is a unique ID agreement number. The format of this is as follows: aaa/bccccc


      aaa is a predefined personnel number.


      b is the last digit of the year - this currently does not update automatically and is just set as "7", and I will manually have to change this in 2018.


      ccccc is a calculation of how many minutes we are into the year, divided by 5.25 (to keep the number as 99,999 or less during work days of the year, so this number is never more than five digits)


      The problem I'm facing is that if ccccc is below five digits then the agreement number will be too short. Is there any way that I can force this part of the script to return five digits including leading zeroes? The calculation script I'm currently using is below:



      var dd = "01/01/17 00:00";

      var rd = util.printd("dd/mm/yy HH:MM", new Date());



      var d1 = util.scand("dd/mm/yy HH:MM", dd);

      var d2 = util.scand("dd/mm/yy HH:MM", rd);



      var diff = (d2.valueOf() - d1.valueOf()) / 1000;



      event.value = "326/7" + Math.round((diff / 60 /5.25));



      In the above coding "326" is the personnel number so this is always set manually.


      Whilst I'm here, is there also a way that the b section of the equation (the last digit of the year) can be automatically updated each year as well?


      Many thanks,


      Tom Seager