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

Calculated field BG color change automatically

Explorer ,
Nov 21, 2023 Nov 21, 2023

Copy link to clipboard

Copied

Hey guys. I have a query.

I have 3 fields = A, B and C

C = B/A. This is the simplified calculation for C.

 

Now I want C field to change its bg color to green when B is greater than A

and if B is less than A, then red.

 

I have tried so many things and formulae but unable to succeed, please help 😞 

TOPICS
Create PDFs , How to , JavaScript , PDF , PDF forms

Views

165

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Nov 21, 2023 Nov 21, 2023

If you use simplified notation for division, you will get an error when field A is empty.
Instead, try something like this as custom calculation script of field "C":

var a = Number(this.getField("A").valueAsString);
var b = Number(this.getField("B").valueAsString);

if(!isNaN(a) && !isNaN(b) && a !== 0)
event.value = b/a;
else
event.value = "";

if((!isNaN(a) && !isNaN(b)) && (a !== 0 && b !== 0)){
if(b>a)
event.target.fillColor = color.green;
else if(b<a)
event.target.fillColor = color.red;}
els
...

Votes

Translate

Translate
Community Expert ,
Nov 21, 2023 Nov 21, 2023

Copy link to clipboard

Copied

If you use simplified notation for division, you will get an error when field A is empty.
Instead, try something like this as custom calculation script of field "C":

var a = Number(this.getField("A").valueAsString);
var b = Number(this.getField("B").valueAsString);

if(!isNaN(a) && !isNaN(b) && a !== 0)
event.value = b/a;
else
event.value = "";

if((!isNaN(a) && !isNaN(b)) && (a !== 0 && b !== 0)){
if(b>a)
event.target.fillColor = color.green;
else if(b<a)
event.target.fillColor = color.red;}
else
event.target.fillColor = color.transparent;

Votes

Translate

Translate

Report

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
Explorer ,
Nov 22, 2023 Nov 22, 2023

Copy link to clipboard

Copied

LATEST

Thank you so much, It's perfect!

Votes

Translate

Translate

Report

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