Skip to main content
Participating Frequently
June 5, 2024
Answered

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

  • June 5, 2024
  • 2 replies
  • 4307 views

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!

 

This topic has been closed for replies.
Correct answer Nesa Nurani

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 = "";

2 replies

Nesa Nurani
Nesa NuraniCorrect answer
Community Expert
June 6, 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 = "";
Participating Frequently
June 6, 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.

Nesa Nurani
Community Expert
June 7, 2024

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

try67
Community Expert
June 5, 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.

try67
Community Expert
June 5, 2024

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

Participating Frequently
June 6, 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!