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:
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.
Copy link to clipboard
Copied
Yes.
And depending on the type of field used (text, dropdown, etc.) you may not even need Javascript.
Copy link to clipboard
Copied
I am using a combination of text and dropdown, but dropdown is preferable.
Copy link to clipboard
Copied
I would need assistance how to set that up. Thank you.
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.
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.
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.
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.
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!!
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?
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
Copy link to clipboard
Copied
Not trying to be rude, yet you are. Thank you for everything so far. I will take care of it from here.