Copy link to clipboard
Copied
I need help to write a script within my Form.
A = B x C
Risk = Process Medium x Test Pressure
Where:
B, "Process Medium" drop down. This list has multiple options which I have gave each an Event Value
C, "Test Pressure" but:
less than 5 to give event value 1,
greater than 5 but less than 10 to give event value 2,
greater than 10 but less than 15 to give event value 3,
greater than 15 but less than 20 to give event value 5,
greater than 20 but less than 30 to give event value 10,
greater than 30 to give event value 20.
Finally result in "Risk" text box to display:
Low Risk (in green font) if results is less than 9
Medium Risk (in orange font) if result is greater than 9 but less than 20
High Risk (in red font) if results is greater than 20
Copy link to clipboard
Copied
What is less than than 5...greater than 30?
Copy link to clipboard
Copied
The "Test Pressure" field is a manual input field
So if the user types 14 the event value should be 3?
Then I can take this event value X "Process Medium" Event Value
Copy link to clipboard
Copied
You are missing 5, 10, 15, and 20. Do you mean <=5, <=10, <=15, <=20?
Copy link to clipboard
Copied
<= 5
event value 1
>5 <=10
event value 2
>10 <=15
event value 3
>15 <=20
event value 5
>20 <=30
event value 10
>30
event value 20
Copy link to clipboard
Copied
Enter this custom calculation script in the risk field:
var tpVal = this.getField("Test Pressure").value;
var newVal=0;
if(tpVal<=5){newVal=1}
else if(tpVal<=10){newVal=2}
else if(tpVal<=15){newVal=3}
else if(tpVal<=20){newVal=5}
else if(tpVal<=30){newVal=10}
else {newVal=20}
event.value=this.getField("Process Medium").value * newVal;
if(event.value<=9)
{event.value="Low Risk";event.target.textColor=["RGB",0,0.5,0.25]}
else if(event.value<=20)
{event.value="Medium Risk";event.target.textColor=["RGB",1,0.44,0.007]}
else{event.value="High Risk";event.target.textColor=color.red}
Copy link to clipboard
Copied
Try this as custom calculation script of "Risk" field:
var process = Number(this.getField("Process Medium").valueAsString);
var press = Number(this.getField("Test Pressure").valueAsString);
var totalpress = 0;
var total = 0;
if(press > 0 && press <= 5)
totalpress = 1;
else if(press > 5 && press <= 10)
totalpress = 2;
else if(press > 10 && press <= 15)
totalpress = 3;
else if(press > 15 && press <= 20)
totalpress = 5;
else if(press > 20 && press <= 30)
totalpress = 10;
else if(press > 30)
totalpress = 20;
total = process*totalpress;
if(total == 0)
event.value = "";
else{
if(total > 0 && total <= 9){
event.value = "Low Risk";
event.target.textColor = color.green;}
else if(total > 9 && total <= 20){
event.value = "Medium Risk";
event.target.textColor = ["RGB", 1, 0.647, 0];}
else if(total > 20){
event.value = "High Risk";
event.target.textColor = color.red;}}
Copy link to clipboard
Copied
Thanks for your help!!!
Script works perfect.