Expand my Community achievements bar.

SOLVED

## defining months to use in calculation

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

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";
}
}```
5 Replies

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";
}
}```

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?

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.

Level 5

Yes, I have a field named MonthTraveled

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!