When you get the "value" of a field, it will interpret anything that looks like a number as a number - and that means that leading zeroes will get removed. Use the "valueAsString" property instead. This will preserve leading zeros:
var someVariable = this.getField("someName").valueAsString;
First of all, don't use the value property, but valueAsString. The former will strip any leading zeros...
What's missing in your code is a bit of RegExp magic. Namely, the control characters that indicate the start or end of a string.
So, to remove any leading zeros you can use this RegExp:
And to remove any trailing zeros use this one:
^ - The start of a string
$ - The end of a string
+ - Match one or more characters (in case there's more than one zero at the start/end of the string, I assume you want to remove them all, not just the first one)
Hi try67 and Karl,
Thank you both so much for your replys. I really appreciate it!
I updated my script to be this:
var someVariable = (this.getField("purch_order").valueAsString().replace(/0/,"") + "-" + this.getField("clin").valueAsString().replace(/^0+/,"") + "-" + this.getField("body_sn").valueAsString().replace(/0/,""));
But, now it doesn't work.Any Ideas?