Copy link to clipboard
Copied
Hello All.
Here is my problem.
Field "A" is populated from a previous calculation.
Next calulation is A x B x C = D.
If B and C is 0 (zero), then D will diplay 0 (zero)
If B & C are left blank, then D will display an empty field
Field A & D are read only
I've a can't seem to finds a script that applies to the above.
I would appreciate any help.
Thanks.
In the custom calculation script for D, you could do something like:
// Custom calculate script
(function () {
// Get the input field values, as strings
var sA = getField("A").valueAsString;
var sB = getField("B").valueAsString;
var sC = getField("C").valueAsString;
if (sB && sC) { // If both of these input fields are not empty...
// If both of these field values are zero when converted to a number...
if (+sB === 0 && +sC === 0) {
event.value
...
Code works. I replaced with incorrect field names.
Thanks George_Johnson-9fk31b
Copy link to clipboard
Copied
In the custom calculation script for D, you could do something like:
// Custom calculate script
(function () {
// Get the input field values, as strings
var sA = getField("A").valueAsString;
var sB = getField("B").valueAsString;
var sC = getField("C").valueAsString;
if (sB && sC) { // If both of these input fields are not empty...
// If both of these field values are zero when converted to a number...
if (+sB === 0 && +sC === 0) {
event.value = 0; // Set this field value to zero
return;
} else {
event.value = sA * sB * sC; // Set this field value to this product
return;
}
} else {
// Blank this field since B and C inputs are blank
event.value = "";
return;
}
})();
You'd have to change the field names in the getField statements to the actual field names. Be sure to set the field calculation order to what makes sense.
Copy link to clipboard
Copied
Sorry.
I get what the script is trying to do but what should I be copying to paste in. I'm getting errors.
The names of my fields are
A=g
B=gg
C=yy
Copy link to clipboard
Copied
It would be helpful to know what the error messages you're getting actually say...
Also, post your full code.
Copy link to clipboard
Copied
The script its what George_Johnson-9fk31b left.
// Custom calculate script (function () { // Get the input field values, as strings var sA = getField("A").valueAsString; var sB = getField("B").valueAsString; var sC = getField("C").valueAsString; if (sB && sC) { // If both of these input fields are not empty... // If both of these field values are zero when converted to a number... if (+sB === 0 && +sC === 0) { event.value = 0; // Set this field value to zero return; } else { event.value = sA * sB * sC; // Set this field value to this product return; } } else { // Blank this field since B and C inputs are blank event.value = ""; return; } })()
Copy link to clipboard
Copied
Code works. I replaced with incorrect field names.
Thanks George_Johnson-9fk31b
Copy link to clipboard
Copied
This condition is not necessary:
If B and C is 0 (zero), then D will display 0 (zero)
If either of those fields is zero then the result of multiplying them by any other value will be zero, no matter what.
Copy link to clipboard
Copied
It's not about the math. It's about what displays.
B & C are populated by user. BUT if they enter a 0 (zero). The resulting field will show 0 (zero). IF they leave it blank then the resulting field will be blank.