Multiple If Statements
Good evening,
I am having trouble adding two dates based on two criteria: selected category field and date.
What I have so far is:
var choose = @choose;
var date4 = @Date 4;
var date5 = @Date 5;
if( choose == "Option 1" || "Option 2" ){ //no additional date only the category chosen
var date1 = @Date 1;
var toAdd = 15; //we want to add 15 days to Date 1 if either Option 1 or Option 2 is selected
var paymentDate = moment( date1 ).add(toAdd, 'days').toDate();
date1
};
if( choose == "Option 3" || "Option 4" && date4 != null ){
var date2 = @Date 2;
var toAdd = 45; // we want to add 45 days to Date 2 if either Option 3 or Option 4 is selected AND Date 4 is not null
var date1 = moment( date2 ).add(toAdd, 'days').toDate();
date2
};
if( choose == "Option 5" || "Option 6" && date5 != null){
var date3 = @Date 3;
var toAdd = 15; //we want to add 15 days if either Option 5 or Option 6 is selected AND Date 5 is not null
var date3 = moment( date3 ).add(toAdd, 'days').toDate();
date3
};
Thank you so much for any help on this!
-
Hi James,
this should work:var date, toAdd,
choose = @choose,
date1 = @Date 1,
date2 = @Date 2,
date3 = @Date 3,
date4 = @Date 4,
date5 = @Date 5;
if( choose == "Option 1" || "Option 2" ){
date = date1;
toAdd = 15;
} else if( choose == "Option 3" || "Option 4" && date4 != null ){
date = date2;
toAdd = 45;
} else if( choose == "Option 5" || "Option 6" && date5 != null){
date = date3;
toAdd = 15;
} else {
date = "";
toAdd = 0;
};
toAdd > 0 ? moment(date).add(toAdd, 'days').toDate() : ""Rainer
Please sign in to leave a comment.
Comments
1 comment