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

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

Community Beginner ,
Nov 06, 2024 Nov 06, 2024

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

Calculation.PNG

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

TOPICS
Al Assistant , Create PDFs , Edit and convert PDFs , How to , PDF forms

Views

418
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 ,
Nov 06, 2024 Nov 06, 2024

Copy link to clipboard

Copied

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

Votes

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 Beginner ,
Nov 06, 2024 Nov 06, 2024

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 

Votes

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 ,
Nov 06, 2024 Nov 06, 2024

Copy link to clipboard

Copied

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

Votes

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 Beginner ,
Nov 06, 2024 Nov 06, 2024

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

Votes

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 ,
Nov 06, 2024 Nov 06, 2024

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}

 

 

 

 

Votes

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 ,
Nov 06, 2024 Nov 06, 2024

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

 

Votes

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 Beginner ,
Nov 07, 2024 Nov 07, 2024

Copy link to clipboard

Copied

Thanks for your help!!!

Script works perfect.

Votes

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 Beginner ,
Feb 16, 2025 Feb 16, 2025

Copy link to clipboard

Copied

Hi Nesa,

 

I have further support required.

 

I need code for making a text box hidden or visibile.

 

I would like:

Text11 to be hidden IF DS PSV dropdown is "No"

Text11 to be visible IF DS PSV dropdown is "Yes"

 

I have gave Yes a value of 1 

and No a value of 2

Votes

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 ,
Feb 16, 2025 Feb 16, 2025

Copy link to clipboard

Copied

As 'Custom calculation script' of dropdown field use this:

this.getField("Text11").display = (event.value == 1) ? 0:1;

Votes

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 Beginner ,
Feb 16, 2025 Feb 16, 2025

Copy link to clipboard

Copied

Awesome thank you so much

Votes

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
Adobe Employee ,
Mar 11, 2025 Mar 11, 2025

Copy link to clipboard

Copied

LATEST

Hi @Deab, 

 

Help us mark the solution correct.

Marking a solution Correct will help others to identify the solution to a similar issue quickly. And it helps in the search.


~Tariq

Votes

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