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

Find the highest risk rating in the work

Explorer ,
May 08, 2023 May 08, 2023

Hi, 

I have a situation here. 

My work requires employess to fill in a risk assessment. Example shown (Figure 1) below

kennethkamchuh21426993_0-1683594003856.png

 

Figure 1

The Risk (R) can be classified as: 

VH = very high

H = High

M = Medium

L = Low

I want to have a field that is able to find the highest risk in the entire work (Figure 2 below).

kennethkamchuh21426993_1-1683594019118.png

 

Figure 2

For example, I would like the field to be able to find the highest risk to be VH according to figure 1. 

Anyone be able to help? Thanks in advance!

 

 

 

 

TOPICS
How to , JavaScript , PDF forms
994
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 ,
May 08, 2023 May 08, 2023

Let's say your fields are named Field1-4 as custom calculation script of field where you want to show result use this:

var V = [];
for(var i=1; i<=4; i++){
if(this.getField("Field"+i).valueAsString != "")
V.push(this.getField("Field"+i).value);}
if(V.length != 0){
 if(V.indexOf("VH")!== -1)event.value = "VH";
 else if(V.indexOf("H")!== -1)event.value = "H";
 else if(V.indexOf("M")!== -1)event.value = "M";
 else if(V.indexOf("L")!== -1)event.value = "L";}
else
event.value = "";
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
Explorer ,
May 09, 2023 May 09, 2023
LATEST

Thanks for this. 

Sorry to ask an additional question.

I have tried to add conditional formatting on top of the script provided but it does not seem to work when I reset the form. I might be missing ";" somewhere in the script. Would you be able to assist? 

Below is the modified script 

var V = [];
for(var i=1; i<=5; i++){
if(this.getField("Risk"+i).valueAsString != "")
V.push(this.getField("Risk"+i).value);}
if(V.length != 0){
 if(V.indexOf("VH")!== -1){event.value = "VH";event.target.fillColor = color.black; 
event.target.textColor = color.white;}
 else if(V.indexOf("H")!== -1)
{event.value = "H";
event.target.fillColor = color.red;event.target.textColor = color.black;} 
 else if(V.indexOf("M")!== -1)
{event.value = "M";
event.target.fillColor = color.yellow;event.target.textColor = color.black;}
 else if(V.indexOf("L")!== -1)
{event.value = "L";
event.target.fillColor = color.green;event.target.textColor = color.black;}
else
event.value = "";
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