Copy link to clipboard
Copied
Hi,
I have a situation here.
My work requires employess to fill in a risk assessment. Example shown (Figure 1) below
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).
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!
Copy link to clipboard
Copied
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 = "";
Copy link to clipboard
Copied
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 = "";