Skip to main content
Participant
June 30, 2024
Answered

If/Else Script with a Yes/No Condition

  • June 30, 2024
  • 1 reply
  • 497 views

I am trying to create a custom calculation that says...

If TotalExpense < or = DiscretionaryIncome then Seed Funding Text Field Shows "No"

 

If TotalExpense > DiscretionaryIncome then Seed Funding Text Field Shows "Yes"

 

Can anyone help me with this code?

Have anyone written anything like this before?

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

Use this as custom calculation script of "Seed Funding" field:

var Texpense = this.getField("TotalExpense").valueAsString;
var Dincome = this.getField("DiscretionaryIncome").valueAsString;

if(Texpense === "" || Dincome === "") {
 event.value = "";} 
else {
 Texpense = Number(Texpense);
 Dincome = Number(Dincome);
 
if(Texpense <= Dincome)
 event.value = "No";
else if(Texpense > Dincome)
 event.value = "Yes";}

1 reply

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
June 30, 2024

Use this as custom calculation script of "Seed Funding" field:

var Texpense = this.getField("TotalExpense").valueAsString;
var Dincome = this.getField("DiscretionaryIncome").valueAsString;

if(Texpense === "" || Dincome === "") {
 event.value = "";} 
else {
 Texpense = Number(Texpense);
 Dincome = Number(Dincome);
 
if(Texpense <= Dincome)
 event.value = "No";
else if(Texpense > Dincome)
 event.value = "Yes";}
Participant
July 1, 2024

Thank you, Nesa. It worked like a charm! 
I appreciate the help!