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

5 variable fields into 4 different paragraphs, command written, which fields need custom calcs?

New Here ,
Jun 05, 2024 Jun 05, 2024

I am attempting to create a form that has 5 variable selection fields show in referenced spots within a paragraph. 

 

There a 4 paragraphs to choose from in the very first dropdown question. 

 

This is what I have written, but am confused by which fields need custom calculations. 

 

Dropdown3 is the first paragraph driver and the other 5 variable input fields are below.

 

const frequency = this.getField('Dropdown8').value
const date = this.getField('Date7_af_date').value
const target = this.getField('Text9').value
const calcmonths = this.getField('Text99').value
const periodend = this.getField('Dropdown88').value

 

// Function to update Text5 based on Dropdown3 selection
function updateText5 () {
const dropdown3Value = this.getField('Dropdown3').value
const text5Field = this.getField('Text5')

 

if (dropdown3Value === 'Consolidate Debt Service Coverage Ratio C&I, CRE, AgCash, Non-Profit') {
text5Field.value = 'This is test paragraph 1 ' + target + and ' + frequency + ' and ' + calcmonths + ' and ' + date + " and " + calcmonths + ' end paragraph.'
} else if (dropdown3Value === 'Consolidate Debt Service Coverage Ratio, Less Distributions C&I, CRE, AgCash') {
text5Field.value = 'This is a test of paragraph 2 ' + frequency + ' and ' + date + ' and ' + target + '.'
} else if (dropdown3Value === 'Consolidate Minimum Current Ratio C&I, CRE') {
text5Field.value = 'This a test paragrapgh 3 ' + target + ' and ' + periodend + ' and ' + date + '.'
} else if (dropdown3Value === 'Consolidate Maximum Debt/TNW C&I, CRE') {
text5Field.value = 'This is a test paragraph 4' + target + 'and ' + periodend + ' and ' + calcmonths + " end."
}
}

// Set the custom calculation script for Dropdown3 to update Text5
this.getField("Dropdown3").setAction("Validate", "updateText5();");

// Initial call to set the value of Text5 based on the current selection of Dropdown3
updateText5();

 

 

Thank you!

 

TOPICS
JavaScript , PDF forms
4.5K
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 ,
Jun 05, 2024 Jun 05, 2024

Use this as custom calculation script of "Text5" field:

var frequency = this.getField("Dropdown8").valueAsString;
var date = this.getField("Date7_af_date").valueAsString;
var target = this.getField("Text9").valueAsString;
var calcmonths = this.getField("Text99").valueAsString;
var periodend = this.getField("Dropdown88").valueAsString;
var dropdown3Value = this.getField("Dropdown3").valueAsString;

if (dropdown3Value === "Consolidate Debt Service Coverage Ratio C&I, CRE, AgCash, Non-Profit") {
 event.value = "This is test paragraph 1 " + target + " and " + frequency + " and " + calcmonths + " and " + date + " and " + calcmonths + " end paragraph.";} 
else if (dropdown3Value === "Consolidate Debt Service Coverage Ratio, Less Distributions C&I, CRE, AgCash") {
 event.value = "This is a test of paragraph 2 " + frequency + " and " + date + " and " + target + ".";} 
else if (dropdown3Value === "Consolidate Minimum Current Ratio C&I, CRE") {
 event.value = "This a test paragraph 3 " + target + " and " + periodend + " and " + date + ".";} 
else if (dropdown3Value === "Consolidate Maximum Debt/TNW C&I, CRE") {
 event.value = "This is a test paragraph 4 " + target + " and " + periodend + " and " + calcmonths + " end.";}
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 ,
Jun 05, 2024 Jun 05, 2024

- Use var instead of const.

- The setAction line should only be used once, from the Console. Do not include it in your code.

Also, it says that it's setting a calculation script, when in fact it's a validation one.

- The last line (the call to the updateText5 function) should be removed entirely.

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 ,
Jun 05, 2024 Jun 05, 2024

Also, move all of the variable definitions into the function.

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
New Here ,
Jun 06, 2024 Jun 06, 2024

Thank you for this,

 

I am a little confused by what you refer to when you say Console? 

 

I updated the cont to var. 

 

Really apprecaite your help! 

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

The JS Console is where you execute code without it being a part of a file.

See: https://acrobatusers.com/tutorials/javascript_console

 

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
New Here ,
Jun 06, 2024 Jun 06, 2024

Thank you, this is what I recieve. 

 

Maybe im misunderstanding? 

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

This is correct.

Look at the properties of the dropdown.

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
New Here ,
Jun 10, 2024 Jun 10, 2024

I appreciate your help. 

 

Attached is a snip of the Text5 proprties. 

 

{
var dropdown3Value = this.getField('Dropdown3').value
var text5Field = this.getField('Text5')
var frequency = this.getField('Dropdown8').value
var date = this.getField('Date7_af_date').value
var target = this.getField('Text9').value
var calcmonths = this.getField('Text99').value
var periodend = this.getField('Dropdown88').value

if (dropdown3Value === 'Consolidate Debt Service Coverage Ratio C&I, CRE, AgCash, Non-Profit') {
text5Field.value = 'This is test paragraph 1 ' + target + ' and ' + frequency + ' and ' + calcmonths + ' and ' + date + " and " + calcmonths + ' end paragraph.'
} else if (dropdown3Value === 'Consolidate Debt Service Coverage Ratio, Less Distributions C&I, CRE, AgCash') {
text5Field.value = 'This is a test of paragraph 2 ' + frequency + ' and ' + date + ' and ' + target + '.'
} else if (dropdown3Value === 'Consolidate Minimum Current Ratio C&I, CRE') {
text5Field.value = 'This a test paragrapgh 3 ' + target + ' and ' + periodend + ' and ' + date + '.'
} else if (dropdown3Value === 'Consolidate Maximum Debt/TNW C&I, CRE') {
text5Field.value = 'This is a test paragraph 4' + target + 'and ' + periodend + ' and ' + calcmonths + " end."
}
}

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 ,
Jun 05, 2024 Jun 05, 2024

Use this as custom calculation script of "Text5" field:

var frequency = this.getField("Dropdown8").valueAsString;
var date = this.getField("Date7_af_date").valueAsString;
var target = this.getField("Text9").valueAsString;
var calcmonths = this.getField("Text99").valueAsString;
var periodend = this.getField("Dropdown88").valueAsString;
var dropdown3Value = this.getField("Dropdown3").valueAsString;

if (dropdown3Value === "Consolidate Debt Service Coverage Ratio C&I, CRE, AgCash, Non-Profit") {
 event.value = "This is test paragraph 1 " + target + " and " + frequency + " and " + calcmonths + " and " + date + " and " + calcmonths + " end paragraph.";} 
else if (dropdown3Value === "Consolidate Debt Service Coverage Ratio, Less Distributions C&I, CRE, AgCash") {
 event.value = "This is a test of paragraph 2 " + frequency + " and " + date + " and " + target + ".";} 
else if (dropdown3Value === "Consolidate Minimum Current Ratio C&I, CRE") {
 event.value = "This a test paragraph 3 " + target + " and " + periodend + " and " + date + ".";} 
else if (dropdown3Value === "Consolidate Maximum Debt/TNW C&I, CRE") {
 event.value = "This is a test paragraph 4 " + target + " and " + periodend + " and " + calcmonths + " end.";}
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
New Here ,
Jun 06, 2024 Jun 06, 2024

I appreciate the response Nesa, unfortunetly this is not working. Text5 is blank. I did not get any errors but not sure what I am missing. 

 

Attached is a snip of the form.

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

Did you place script in "Text5" field under 'Custom calculation script' ?

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
New Here ,
Jun 10, 2024 Jun 10, 2024

I appreciate your continued help.

 

Yes, I did. 

 

Please see my snip. 

 

Thank you! 

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 ,
Jun 10, 2024 Jun 10, 2024

You're not using the code provided by Nesa. You need to use event.value to assign the new value, not text5Field.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
New Here ,
Jun 11, 2024 Jun 11, 2024

Thanks for the response, I copied her code as above and put it in the custom calculation box?

 

Can you explain what you are refering to? 

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 ,
Jun 11, 2024 Jun 11, 2024

I think I did...

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
New Here ,
Jun 11, 2024 Jun 11, 2024

I copied Nesa's code and pasted into the custom calc box in text5 properties. 

 

Am I not understanding something? 

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 ,
Jun 11, 2024 Jun 11, 2024
LATEST

In your last post the code you posted was different. If you copied it directly, without editing it, then it should work.

If it doesn't, check the JS Console (Ctrl+J) for error messages.

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