Skip to main content
Participant
February 19, 2025
해결됨

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

  • February 19, 2025
  • 2 답변들
  • 481 조회

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.

최고의 답변: Nesa Nurani

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

2 답변

melissaHOR작성자
Participant
February 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

Nesa Nurani
Community Expert
Community Expert
February 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);}}}
melissaHOR작성자
Participant
February 27, 2025

Thanks this is great. 

Nesa Nurani
Community Expert
Community Expert
February 19, 2025

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