Copy link to clipboard
Copied
I'm working on a form that compares two sets of numbers, the first of which can result in a NaN result until data is plugged in. I have tried a handful of things, but wherever I plug in the NaN suppressing code, I end up hiding the actual results when there are numbers, so I'm turning to you lovely people!
I currently have the following code in a custom calculation script:
var CHANGEA=this.getField("CurrentMeetA").value - this.getField("CombineMeetA").value;
if (CHANGEA>=0) event.value = Math.round(CHANGEA) + "\n fewer";
else event.value = Math.round(Math.abs(CHANGEA)) + "\n more"
event.target.textColor = CHANGEA >= 0 ? ["RGB", 0.3137 , 0.702, 0.2471 ] : ["RGB", 0.9373 , 0.2784, 0.1765 ];
I'm fine if it shows a "0 fewer" result (as it does for the quarterly, monthly, and weekly columns based on the annual column when the form is blank), but don't want a NaN result before people fill in the form.
Below is the form itself in case my description is confusing.
Thank you for your assistance! I am pretty stoked to have gotten as far as I did without running into a wall, but this part is my last hurdle and I've tried several approaches with no luck!
Hi,
You should be able to change you code to this :
var CHANGEA=this.getField("CurrentMeetA").value - this.getField("CombineMeetA").value;
if (isNaN(CHANGEA)){
CHANGEA=0;
}
if (CHANGEA>=0) event.value = Math.round(CHANGEA) + "\n fewer";
else event.value = Math.round(Math.abs(CHANGEA)) + "\n more"
Malcolm
Copy link to clipboard
Copied
Hi,
You should be able to change you code to this :
var CHANGEA=this.getField("CurrentMeetA").value - this.getField("CombineMeetA").value;
if (isNaN(CHANGEA)){
CHANGEA=0;
}
if (CHANGEA>=0) event.value = Math.round(CHANGEA) + "\n fewer";
else event.value = Math.round(Math.abs(CHANGEA)) + "\n more"
Malcolm
Copy link to clipboard
Copied
Ahhh, perfect! Thank you so much!
Copy link to clipboard
Copied
Did you format your fields to number?
Copy link to clipboard
Copied
No, I did not, because I needed the field to return text after the number, so I assumed formatting to a number would cause a conflict.