Copy link to clipboard
Copied
I'm new to this java business...
I need help defaulting to the amount in field A if the true total of fields b, c, d, e, etc (TrueTotal) is greater than A.
if A = TrueTotal value = truetotal
if A <TrueTotal, then default to A, notify user that amount doesn't match
if A>TrueTotal, then TrueTotal, notify user that amounts don't match and A is too high
Thanks so much.
Copy link to clipboard
Copied
So you just want to show messages?
This will show messages when all fields are filled, place it as custom calculation script of any text field:
var fields = ["A", "B", "C", "D", "E"];
var values = fields.map(name => this.getField(name).valueAsString);
if (event.source && fields.indexOf(event.source.name) !== -1) {
if (values.every(v => v !== "")) {
var [a, b, c, d, e] = values.map(Number);
var trueTotal = b + c + d + e;
if (a < trueTotal) {
app.alert("Warning: The amount entered in field A is lower than the total calculated amount.", 3);}
else if (a > trueTotal) {
app.alert("Warning: The amount in field A is too high and does not match the calculated total.", 3);}}}
Copy link to clipboard
Copied
Do you wish to show the result in "A" field or another field?
Should all fields be filled before checking?
Copy link to clipboard
Copied
Wow. So fast! Thank you.
The value of A is static and the true total is sum of other values. I need to show the messages. I can have a hidden field for actual if that helps
Copy link to clipboard
Copied
So you just want to show messages?
This will show messages when all fields are filled, place it as custom calculation script of any text field:
var fields = ["A", "B", "C", "D", "E"];
var values = fields.map(name => this.getField(name).valueAsString);
if (event.source && fields.indexOf(event.source.name) !== -1) {
if (values.every(v => v !== "")) {
var [a, b, c, d, e] = values.map(Number);
var trueTotal = b + c + d + e;
if (a < trueTotal) {
app.alert("Warning: The amount entered in field A is lower than the total calculated amount.", 3);}
else if (a > trueTotal) {
app.alert("Warning: The amount in field A is too high and does not match the calculated total.", 3);}}}
Copy link to clipboard
Copied
Thanks this is great.
Copy link to clipboard
Copied
Hi @melissaHOR,
Hope you are doing well.
Please feel free to leave an upvote or mark the statement as a correct answer for future users to use as a reference.
Regards,
Souvik.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more