Using .value vs .valueAsString
Please help me understand when to use .valueAsString instead of just .value. Below is the calculation I used (in black), with the portions in red added when I asked for help from this group in making it work. Since this is a form to be completed either manually or as a fill-in, I also used a validation script on A and B fields: if(event.value == 0) event.value = "";. The second part of my question, does it hurt to use vAS even when you don't need it?
I read the JS Reference and I think I understand "It differs from value, which attempts to convert the contents of a field contents to an accepted format. For example, for a field with a value of “020”, value returns the integer 20, while valueAsString returns the string “020”.
Here's my thought - showing fields A & B as .valueAsString changed it to a undetermined format, which then had to be manually shown to be a number by the addition of A=Number(A). But why did it need to be done in the first place? Was it something to do with the "" blanks or validation, or maybe number & text in same statement? Understanding why will help my in future queries.
If you can "dumb it down" for me into a beginner's explanation, I would greatly appreciate it -LOL!
TIA ~ Michelle
var A = this.getField("CD#Expect").valueAsString; // Expected Activity for period reviewed;
var B = this.getField("CD#MoTotal").valueAsString; // Actual Activity for period reviewed;
if (A=="" && B=="") event.value = "";
else {
A = Number(A);
B = Number(B);
if (B>A) event.value = "Exceeds";
else if (B<A) event.value = "Under";
else if (B==A) event.value = "Meets";
}
