Skip to main content
Participating Frequently
November 7, 2024
Question

Help with script for for a calculation looking at two fields to give a text result

  • November 7, 2024
  • 2 replies
  • 856 views

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

2 replies

Nesa Nurani
Community Expert
Community Expert
November 7, 2024

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;}}

 

Participating Frequently
November 7, 2024

Thanks for your help!!!

Script works perfect.

PDF Automation Station
Community Expert
Community Expert
November 7, 2024

What is less than than 5...greater than 30?

Participating Frequently
November 7, 2024

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 

PDF Automation Station
Community Expert
Community Expert
November 7, 2024

You are missing 5, 10, 15, and 20.  Do you mean <=5,  <=10, <=15, <=20?