Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Field equals lesser of two values; one field sum of multiples, other is value

New Here ,
Feb 18, 2025 Feb 18, 2025

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.

TOPICS
How to , JavaScript , PDF forms
545
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Feb 19, 2025 Feb 19, 2025

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);}}}

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 18, 2025 Feb 18, 2025

Do you wish to show the result in "A" field or another field?
Should all fields be filled before checking?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 19, 2025 Feb 19, 2025

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 19, 2025 Feb 19, 2025

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);}}}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 27, 2025 Feb 27, 2025

Thanks this is great. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Apr 25, 2025 Apr 25, 2025
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines