1 Reply Latest reply on Apr 22, 2014 10:11 PM by George_Johnson

    Can't get leading 0's to begin before a certain field with max characters allowed?

    hpdouet

      I use several text fieds that populate into another text field used as a barcode with a limit of 44 characters.  The var AcctNO has a limit of 10 characters (some could be leading 0's and shouldn't be removed).  The Var BoxNO has a limit of 10 characters (some could be leading 0's and shouldn't be removed). The Var SSN1 has a limit of 9 characters (no leading 0's are removed).The Var DOCTYPECODE has a limit of 5 characters. The Var DOCDATE has a limit of 10 charachers but the calculation script removes the "/" "/" (leading 0's are not removed).

       

      This is the custom calculation script I am using:

       

      // Custom calculation script

      (function () {

      // Get the field values, as strings

      var AcctNO = getField("AcctNO").valueAsString;

      var BoxNO = getField("BoxNO").valueAsString;

      var SSN1 = getField("SSN1").valueAsString;

      var DOCTYPECODE = getField("DOCTYPECODE").valueAsString;

      var DOCDATE = getField("DOCDATE").valueAsString;

      var PageNO = getField("PageNO").valueAsString;

      // Set this field value by concatenating the field values

      event.value = (AcctNO + SSN1+ DOCTYPECODE + DOCDATE + PageNO + BoxNO).replace("/","", "g");

      })();

      // Custom Format script

      (function () {

      // Get the character limit for this field

      var max_chars = event.target.charLimit;

      // Define the pad character to use

      var pad_char = "0";

      // If the field is not blank and there is a character limit, pad value with leading zeroes

      if (event.value && max_chars) {

      event.value = (new Array(max_chars + 1).join(pad_char) + event.value).slice(-max_chars);

      }

      })();

      event.value = "*" + event.value + "*";

       

       

      If all fields are keyed correctly then the barcode should read like this:

      *0123456789222222222K702504232013010000001234*

       

      But it is reading like this instead:

      *00000001234567891234222222222K70250424201401*

       

      What do I need to change in order for this to work correctly?