Expand my Community achievements bar.

SOLVED

defining months to use in calculation

Avatar

Level 5

Trying to take a range of month/date to utilize in calculation below...

 

var d = new Date(this.rawValue);
YearTraveled.rawValue = d.getYear()+1900

 

if (this.resolveNode("YearTraveled").rawValue == "2020") {
this.resolveNode("TravelReimbursement").rawValue = ".575";
}
if (this.resolveNode("YearTraveled").rawValue == "2021") {
this.resolveNode("TravelReimbursement").rawValue = ".560";

 

I want the next action to say...

if MonthTraveled is (July 2022 thru December 2022)

this.resolveNode("TravelReimbursement").rawValue = ".625";

 

 

 

1 Accepted Solution

Avatar

Correct answer by
Level 5

Try this

var d = new Date(this.rawValue);
YearTraveled.rawValue = d.getFullYear();
MonthTraveled.rawValue = d.getMonth() + 1;
TravelReimbursement.rawValue = "";

if (YearTraveled.rawValue == "2020") {
	TravelReimbursement.rawValue = ".575";
	
} else if (YearTraveled.rawValue == "2021") {
	TravelReimbursement.rawValue = ".560";
	
} else if (YearTraveled.rawValue == "2022") {
	if ((MonthTraveled.rawValue >= 7) && (MonthTraveled.rawValue <= 12)) {
		TravelReimbursement.rawValue = ".625";
	}
}

View solution in original post

5 Replies

Avatar

Correct answer by
Level 5

Try this

var d = new Date(this.rawValue);
YearTraveled.rawValue = d.getFullYear();
MonthTraveled.rawValue = d.getMonth() + 1;
TravelReimbursement.rawValue = "";

if (YearTraveled.rawValue == "2020") {
	TravelReimbursement.rawValue = ".575";
	
} else if (YearTraveled.rawValue == "2021") {
	TravelReimbursement.rawValue = ".560";
	
} else if (YearTraveled.rawValue == "2022") {
	if ((MonthTraveled.rawValue >= 7) && (MonthTraveled.rawValue <= 12)) {
		TravelReimbursement.rawValue = ".625";
	}
}

Avatar

Level 5

Good morning.

 

This works up until the last condition.  Probably something small I'm missing.  Is there a way I can share my file for you to review?

Avatar

Level 5

Have you got a field named MonthTraveled ?  
You could just use variables as well.

Actually not sure what the preferred method of sharing files is on this forum.

Avatar

Level 5

Made a slight change and it worked....

 

 

var d = new Date(this.rawValue);
YearTraveled.rawValue = d.getYear()+1900;
MonthTraveled.rawValue = d.getMonth() +1;
TravelReimbursement.rawValue = "";

if (YearTraveled.rawValue == "2020") {
TravelReimbursement.rawValue = ".575";
}
else if (YearTraveled.rawValue == "2021") {
TravelReimbursement.rawValue = ".560";
}
else if ((YearTraveled.rawValue == "2022") && (MonthTraveled.rawValue <= 6)) {
TravelReimbursement.rawValue = ".585";
}
else if ((YearTraveled.rawValue == "2022") && (MonthTraveled.rawValue >= 7)) {
TravelReimbursement.rawValue = ".625";
}

 

Team work...      thanks for your help!