Copy link to clipboard
Copied
I have a drop down field (A or B) that needs to be selected based on the value of two other fields
if C > D Dropdown = A
If C < D Drowpdown = B
How can I write this?
I am definitely new to this and have googled quite a few other answers, but this one is hard to narrow down.
Thx in advance
Copy link to clipboard
Copied
Yes. Replace this line:
event.value = (numC >= numD) ? "Accept" : "Reject";
With:
if (numC >= numD) {
event.value = "Accept";
event.target.textColor = color.green;
} else {
event.value = "Reject";
event.target.textColor = color.red;
}
Copy link to clipboard
Copied
You could use a text field instead of dropdown if you only have two values "A" and "B", and use this as custom calculation script of that text field:
var c = this.getField("C").valueAsString;
var d = this.getField("D").valueAsString;
if (c && d) {
var numC = Number(c);
var numD = Number(d);
if (!isNaN(numC) && !isNaN(numD)) {
event.value = numC > numD ? "A" : numC < numD ? "B" : "";}}
else {
event.value = "";}
Copy link to clipboard
Copied
I udated the letters to match the box names and copied this into the script box and it said:
syntaxError: missing ; before statement 5: at line 6
Copy link to clipboard
Copied
What should the field's value be if C equals D?
Copy link to clipboard
Copied
a = Accept
b = Reject
c = MaxGrossRent
d = GrossRent
GrossRent>MaxGrossRent=Accept
GrossRent<MaxGrossRent=Reject
Copy link to clipboard
Copied
My bad. if C=D it is Accept
GrossRent=>MaxGrossRent=Accept
GrossRent<MaxGrossRent=Reject
Copy link to clipboard
Copied
What about if one of those fields has a value and the other doesn't, or both don't have a value?
Copy link to clipboard
Copied
Well, once someone fills out the other areas, the value in those fields will be a number based on the calculation in there.
if the form is first opened and all of the fields are 0, the accept/reject field can be blank.
Copy link to clipboard
Copied
Use this code as the custom calculation script of your field (based on Nesa's code from earlier):
var c = this.getField("GrossRent").valueAsString;
var d = this.getField("MaxGrossRent").valueAsString;
if (c && d) {
var numC = Number(c);
var numD = Number(d);
event.value = (numC >= numD) ? "Accept" : "Reject";
} else {
event.value = "";
}
Copy link to clipboard
Copied
Thank you. I got the form to update when i update the other numbers. just waiting to hear back from someone to verify the numbers and calculations are correct.
Copy link to clipboard
Copied
Thanks to you both. I got the form updated and checked and it is working perfectly for what i need!
One last thing. Is there a way to make the words show up in a certain color? Green for Accept - Red for Reject?
Copy link to clipboard
Copied
Yes. Replace this line:
event.value = (numC >= numD) ? "Accept" : "Reject";
With:
if (numC >= numD) {
event.value = "Accept";
event.target.textColor = color.green;
} else {
event.value = "Reject";
event.target.textColor = color.red;
}
Copy link to clipboard
Copied
Perfect!!!!! Thanks BUNCHES!