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

Need assistance writing a calculation with two conditions

New Here ,
Jul 31, 2023 Jul 31, 2023

This one is a little beyond me so I'm hoping someone can help -

I'm working with 5 fields, I'll label them "fieldA"-"fieldE" for simplicity sake. 

Here is what I'm after: fieldD = fieldB, unless: 1) fieldE is greater than 50,000 and 2) fieldB is null, then fieldD = fieldC. 

Field D is where the calculation would be. 

Example 1:

fieldA: $100,000

fieldB: null (not sure how to express this in the field itself, does null or N/A work, or leaving it blank wihtout it reading as 0?)

fieldC: $60

fieldD: (result should be $60)

fieldE: $150,000

Example 2:

fieldA: $95,000

fieldB: $20

fieldC: (this will default as a 0.00)

fieldD: (result should be $20)

fieldE: $90,000

Thanks all of you wonderful people! 

TOPICS
How to , JavaScript , PDF forms
340
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 ,
Aug 01, 2023 Aug 01, 2023

Null, an empty string and zero are not the same things, so it's important to know what you're dealing with.

Assuming it's a blank field, you can use this code as the custom calculation script of fieldD:

 

var fieldB = this.getField("fieldB").valueAsString;
var fieldC = this.getField("fieldC").valueAsString;
var fieldE = this.getField("fieldE").valueAsString;

if (Number(fieldE)>50000 && fieldB=="") event.value = fieldC;
else event.value = fieldB;

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 ,
Aug 01, 2023 Aug 01, 2023

Null, an empty string and zero are not the same things, so it's important to know what you're dealing with.

Assuming it's a blank field, you can use this code as the custom calculation script of fieldD:

 

var fieldB = this.getField("fieldB").valueAsString;
var fieldC = this.getField("fieldC").valueAsString;
var fieldE = this.getField("fieldE").valueAsString;

if (Number(fieldE)>50000 && fieldB=="") event.value = fieldC;
else event.value = fieldB;
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 ,
Aug 01, 2023 Aug 01, 2023
LATEST

PS. fieldA doesn't seem to have a role in this formula...

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