Copy link to clipboard
Copied
I have a calculated field "C". It is the result of subtracting two other fields, "A" and "B".
I need the value of "C" to populate a new field, "D" if the value of "C" is > 0 and populate "E" if the value of "C" is < 0.
I'm sure this is simple, but I would appreciate your help.
Thanks!
Thom's code is good, but not sufficient. It should also clear those fields when the answer needs to go to the over one. Use this version, instead:
...event.value = Number(this.getField("A").value) - Number(this.getField("B").value);
if (event.value > 0) {
this.getField("D").value = event.value;
this.getField("E").value = "";
} else if (event.value < 0) {
this.getField("D").value = "";
this.getField("E").value = Math.abs(event.value);
} else if (event.value==0) {
this.getField("D").val
Copy link to clipboard
Copied
You'll need to use a Custom JavaScript calculation for this:
event.value = this.getField("A").value - this.getField("B").value;
if(event.value > 0)
this.getField("D").value = event.value;
else if(event.value < 0)
this.getField("E").value = event.value;
This code does exactly what you requested. However, it does not cover the situationd you did not mention
1. What happens when "C" == 0 ?
2. What happens to D and E when the other field gets the value?
Copy link to clipboard
Copied
Thanks so much, Thom! Your answer is SO close!!
If the answer is 0, nothing needs to go in either field, since no money will go to anyone.
But your question about what happens to the other field once we know where the answer goes is spot on. Only one field needs to be filled in--"D" if the answer is positive or "E" if the answer is negative. How can I get it to give me only one answer? It seems that since I have to type in the "A" field info first, it automatically assumes the result will be positive, even if the final result is negative (because there are more debits than credits in the fields)--see below
(Lastly, is there a way to get rid of the minus sign ("-") for the Amount due? If not, no worries. You've been a big help!
Copy link to clipboard
Copied
Thom's code is good, but not sufficient. It should also clear those fields when the answer needs to go to the over one. Use this version, instead:
event.value = Number(this.getField("A").value) - Number(this.getField("B").value);
if (event.value > 0) {
this.getField("D").value = event.value;
this.getField("E").value = "";
} else if (event.value < 0) {
this.getField("D").value = "";
this.getField("E").value = Math.abs(event.value);
} else if (event.value==0) {
this.getField("D").value = "";
this.getField("E").value = "";
}
Edit: Code fixed
Copy link to clipboard
Copied
Thanks. I plugged the new info in and got an error message:
Copy link to clipboard
Copied
My bad... Add an opening curly bracket in line 2:
if (event.value > 0) {
Copy link to clipboard
Copied
I must be doing something wrong. I added the opening bracket, but now get this error message:
Copy link to clipboard
Copied
You added it in the wrong place. Copy the code from my previous reply. I fixed it there...
Copy link to clipboard
Copied
I figured I'd messed it up!
Thanks so much! It works perfectly!