Script for a formula

New Here ,
May 08, 2020 May 08, 2020

Copy link to clipboard

Copied

Good Morning,

 

I have a question about inputting a formula (java script) into a pdf form.

 

This is the calculation:

 

  • First column is the inherent risk exposure (indicated as Inherent RE 1, 2, 3…7). This column will produce a result that is a number.
  • Second column is risk mitigation strategies (indicated as Risk Mitigation Controls Values Rating 1, 2, 3…7), which can be “strong”, “adequate” or “weak”. This column will be indicated in those words.
  • Third column is the residual risk exposure (indicated as Residual RE 1, 2, 3…7), which needs a formula to produce a result. According to the table, if the inherent risk exposure is of a certain value, applying risk mitigation strategies will produce a number result in the residual risk exposure.

 

For example:

 

If the inherent risk exposure is 25 and we indicate risk mitigation strategies to be “Strong”, the residual risk exposure should read 16. And so on…

 

Is it possible to produce a script for this formula?

 

Thank you.

Views

282

Likes

Translate

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 Community Professional ,
May 08, 2020 May 08, 2020

Copy link to clipboard

Copied

Yes.
And depending on the type of field used (text, dropdown, etc.) you may not even need Javascript.

Likes

Translate

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
New Here ,
May 08, 2020 May 08, 2020

Copy link to clipboard

Copied

I am using a combination of text and dropdown, but dropdown is preferable. 

Likes

Translate

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
New Here ,
May 08, 2020 May 08, 2020

Copy link to clipboard

Copied

I would need assistance how to set that up. Thank you. 

Likes

Translate

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 Community Professional ,
May 08, 2020 May 08, 2020

Copy link to clipboard

Copied

So the resulting risk is acquired from a table? Then you'll need to create the table as an Array. Then the values from the two dropdowns are used to create the indexes that access the table. Since they are already numbers you're pretty well setup for this

Here's an example 

 

var aRiskExposure = [ [0,0,0],

                                    [0,5,10,20],

                                     [0,12, 15, 30],

                                   ];

 

This just shows the structure of how you can do it, you'll need rows and coloumns for each entry in the table. Each row is the  inherent risk and each column is the mitigation strategy.  Notice the first entries are all zero. That's because array indices in JavaScript start at 0, but the numbers in your selections start at 1. 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

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
New Here ,
May 11, 2020 May 11, 2020

Copy link to clipboard

Copied

I have seven rows in each column (inherent risk, mitigation strategy and residual risk). 

In each row for example:

 

If inherent risk is 5 and mitigation strategy is strong, residual risk is 3. 

 

Each row will have 52 options depending on the inherent risk result and the risk mitigation strategy used. 

 

Likes

Translate

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 Community Professional ,
May 11, 2020 May 11, 2020

Copy link to clipboard

Copied

So, the strategy I proposed will work. Just build your table with arrays, then use the selected values to index into the array. I you need help with this I provide private consulting/training sessions. Contact me through the www.pdfscripting.com site.

 

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

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
New Here ,
May 12, 2020 May 12, 2020

Copy link to clipboard

Copied

I was hoping to obtain this information via forum, as I used to previously. I just need assistance in setting the formula up. Thank you. 

Likes

Translate

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 Community Professional ,
May 12, 2020 May 12, 2020

Copy link to clipboard

Copied

So I already provided you with a winning strategy. But if you need more details, Then

The first part is to recreate your table as an array, as I showed in the first post.

 

Then, on the dropdowns for your two selectors, inherent risk and mitigation strategy, provide export values that are integers, unless they are already integers.

Then use these two values to select a "residual risk" value from the table. 

 

For example, use this code in a calculation script on the residual risk field

 

event.value = aResidualRisk[this.getField("inherent risk".value][this.getField("mitigation strategy")];

 

Done!!

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

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
New Here ,
May 15, 2020 May 15, 2020

Copy link to clipboard

Copied

Thank you for your reply. I am getting a syntax error when entering - so I must be doing something wrong. Are you able to provide me with additional information on how to build a table as an array? 

Likes

Translate

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 Community Professional ,
May 15, 2020 May 15, 2020

Copy link to clipboard

Copied

Yes, there is a syntax error. In JavaScript, all the brackets and parentheses must match up. 

Here's the fixed code:

 

event.value = aResidualRisk[this.getField("inherent risk").value][this.getField("mitigation strategy")];

 

However, I don't see how you are going to do this if you can't catch such a simple error. I'm not being rude, its just you seem to lack the basic skills necessary to this task. I would strongly suggest you get some training on developing JavaScript, or hire an expert. 

https://www.pdfscripting.com/public/main.cfm

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Likes

Translate

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
New Here ,
May 15, 2020 May 15, 2020

Copy link to clipboard

Copied

LATEST

Not trying to be rude, yet you are. Thank you for everything so far. I will take care of it from here. 

Likes

Translate

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