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

Risk Calculation matrix

Explorer ,
May 03, 2023 May 03, 2023

I have this risk calculation matrix (Table below) at work that I need to automate

Briefly, the risk can be calculated by Likelihood and the consequences of an hazard.

e.g. if a user select one cell ("Likelihood") with D and selects the second cell ("Consequences") with 3. Then I want the third cell showing the risk calculated to be M.

The problem is there are so many combinations here, so I don't know what to do.

Anyone can help with the JavaScript of this?

kennethkamchuh21426993_0-1683152966099.png

 

TOPICS
JavaScript , PDF forms
2.3K
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
1 ACCEPTED SOLUTION
Community Expert ,
May 08, 2023 May 08, 2023

You can use this as custom calculation of 3rd field:

var L = this.getField("Likelihood").valueAsString;
var C = this.getField("Consequences").valueAsString;
var S = L+C;
if(S=="A1"||S=="B1"||S=="B2"||S=="C2"||S=="D3"||S=="D4"||S=="E3"||S=="E4"||S=="E5")
event.value = "M";
else if(S=="C1"||S=="D1"||S=="D2"||S=="E1"||S=="E2")
event.value = "L";
else if(S=="A2"||S=="A3"||S=="B3"||S=="B4"||S=="C3"||S=="C4"||S=="D5")
event.value = "H";
else if(S=="A4"||S=="A5"||S=="B5"||S=="C5")
event.value = "VH";
else
event.value = "";

View solution in original post

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 06, 2023 May 06, 2023

For the matrix you can use an array of arrays.

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 07, 2023 May 07, 2023

Apologies, I am quite new to JavaScript and bit of a noob. 
I think I need to do something like this. but not sure how to continue the rest....

C = consequences 

L = Likelihood 

R = Risk 

kennethkamchuh21426993_0-1683507621625.png

 

If the user types in 1 in the "C" cell and C in the "L" cell, I want the answer to return as "L" (Low risk)..

So far I have attempted this but I dunno how to do the rest. 

var C=[[1],[2],[3],[4],[5]];

var L=[[A],[B],[C],[D],[E]];

var R=[["M","M","L","L","L"],["H","M","M","L","L"],["H","H","H","M","M"],["VH","H","H","M","M"],["VH","VH","VH","H","M"]];
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

You can use this as custom calculation of 3rd field:

var L = this.getField("Likelihood").valueAsString;
var C = this.getField("Consequences").valueAsString;
var S = L+C;
if(S=="A1"||S=="B1"||S=="B2"||S=="C2"||S=="D3"||S=="D4"||S=="E3"||S=="E4"||S=="E5")
event.value = "M";
else if(S=="C1"||S=="D1"||S=="D2"||S=="E1"||S=="E2")
event.value = "L";
else if(S=="A2"||S=="A3"||S=="B3"||S=="B4"||S=="C3"||S=="C4"||S=="D5")
event.value = "H";
else if(S=="A4"||S=="A5"||S=="B5"||S=="C5")
event.value = "VH";
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 08, 2023 May 08, 2023
LATEST

Thanks heaps! This works like a champ!

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 07, 2023 May 07, 2023

Is there a logic behind it, or is it pretty much arbitrary what the result is for each combination?

If the latter you'll need to specify it for each combination in your code, using a set of if-else conditions, or a 2D array, as was suggested.

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