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

Conditional formatting based on text input in dropdown box

Explorer ,
May 08, 2023 May 08, 2023

Copy link to clipboard

Copied

Hi, 

I have the follow boxes to calculate the risk of a work process, 

kennethkamchuh21426993_0-1683606002739.png

I want to be able to change the background colour of the fields in the R (Risk) fields based on the following conditions: 

L = Green

M = Yellow

H = Red

VH = Red

below is the current script I have in the R (Risk) fields

var L = this.getField("LPreparation").valueAsString;
var C = this.getField("CPreparation").valueAsString;
var R = L+C;
if(R=="A1"||R=="B1"||R=="B2"||R=="C2"||R=="D3"||R=="D4"||R=="E3"||R=="E4"||R=="E5")
event.value = "M";
else if(R=="C1"||R=="D1"||R=="D2"||R=="E1"||R=="E2")
event.value = "L";
else if(R=="A2"||R=="A3"||R=="B3"||R=="B4"||R=="C3"||R=="C4"||R=="D5")
event.value = "H";
else if(R=="A4"||R=="A5"||R=="B5"||R=="C5")
event.value = "VH";
else
event.value = "";

Would be grateful if anyone can assist with the conditional formatting 

TOPICS
How to , JavaScript , PDF forms

Views

869

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
1 ACCEPTED SOLUTION
Community Expert ,
May 08, 2023 May 08, 2023

Copy link to clipboard

Copied

You can do it like this:

 

var L = this.getField("LPreparation").valueAsString;
var C = this.getField("CPreparation").valueAsString;
var R = L+C;
if(R=="A1"||R=="B1"||R=="B2"||R=="C2"||R=="D3"||R=="D4"||R=="E3"||R=="E4"||R=="E5"){
event.target.fillColor = color.yellow;
event.value = "M";}
else if(R=="C1"||R=="D1"||R=="D2"||R=="E1"||R=="E2"){
event.target.fillColor = color.green;
event.value = "L";}
else if(R=="A2"||R=="A3"||R=="B3"||R=="B4"||R=="C3"||R=="C4"||R=="D5"){
event.target.fillColor = color.red;
event.value = "H";}
else if(R=="A4"||R=="A5"||R=="B5"||R=="C5"){
event.target.fillColor = color.red;
event.value = "VH";}
else{
event.target.fillColor = color.white;
event.value = "";}

 

To see color, you will have to turn off fields highlight in Edit⇾Preferences⇾Forms and uncheck 'Show border hover color for fields'. If other users use the file, they will have to do the same on their software also.

Or since it's a calculated field you can set it to read only, that will remove highlight also.

View solution in original post

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
Community Expert ,
May 08, 2023 May 08, 2023

Copy link to clipboard

Copied

You can do it like this:

 

var L = this.getField("LPreparation").valueAsString;
var C = this.getField("CPreparation").valueAsString;
var R = L+C;
if(R=="A1"||R=="B1"||R=="B2"||R=="C2"||R=="D3"||R=="D4"||R=="E3"||R=="E4"||R=="E5"){
event.target.fillColor = color.yellow;
event.value = "M";}
else if(R=="C1"||R=="D1"||R=="D2"||R=="E1"||R=="E2"){
event.target.fillColor = color.green;
event.value = "L";}
else if(R=="A2"||R=="A3"||R=="B3"||R=="B4"||R=="C3"||R=="C4"||R=="D5"){
event.target.fillColor = color.red;
event.value = "H";}
else if(R=="A4"||R=="A5"||R=="B5"||R=="C5"){
event.target.fillColor = color.red;
event.value = "VH";}
else{
event.target.fillColor = color.white;
event.value = "";}

 

To see color, you will have to turn off fields highlight in Edit⇾Preferences⇾Forms and uncheck 'Show border hover color for fields'. If other users use the file, they will have to do the same on their software also.

Or since it's a calculated field you can set it to read only, that will remove highlight also.

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 ,
May 09, 2023 May 09, 2023

Copy link to clipboard

Copied

LATEST

Amazing! Thank you so much for this!

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