Skip to main content
Participating Frequently
Jun 5, 2024 9:04 PM UTC
Answered

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

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 is closed to new replies. Start a new post to keep the conversation going.
Nesa Nurani
Nesa NuraniCorrect answer
Community Expert
Jun 6, 2024 5:30 AM UTC

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

16 replies

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
Jun 6, 2024 5:30 AM UTC

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
Participating Frequently
Jun 6, 2024 9:15 PM UTC

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
Nesa Nurani
Community Expert
Community Expert
Jun 7, 2024 4:28 AM UTC

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

Translate
try67
Community Expert
Community Expert
Jun 5, 2024 9:45 PM UTC

- 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
try67
Community Expert
Community Expert
Jun 5, 2024 9:52 PM UTC

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

Translate
Participating Frequently
Jun 6, 2024 9:57 PM UTC

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