Validate whether the selected date is inbetween start date and end date in AX2012

Hi.

How to validate whether selected date is in between two dates in AX2012? For ex I have an table called CAEPR having a field called StartDate. And there is another table PRPer with fields caestartdate and caeenddate. In the CAEPR Validate method I need to check if the selected date that is startdate (caper table) whether it is between caestartdate(PrPer) and caeenddate(PrPer). If it is inbetween it should throw a validation message.

The below code is not working .

if(this.caeVoid == 1)

{

if ((this.caeStartDate >= startdt )&& (this.caestartdate <= enddt))

{

ret = ret && checkFailed(“Please select the Max Date for void”);

}

}

Thanks

Thanks…

“Not working” is never a sufficient description. You should explain what exactly happens.

You mentioned CaeEndDate field in your description, but you don’t use it in your code (one the other hand, you refer to some variables that you didn’t mention). Isn’t your bug there? If not, please explain your code, because it doesn’t seem to match your description.

Table PRPer - Field 1 - caestartdate
Field 2 - caeenddate

Table CaePR - Field 1 StartDate
Field 2 CaeVoid (Checkbox)

if ((this.StartDate>= caestartdate )&& (this.StartDate<= caeenddate))

{

ret = ret && checkFailed(“Please select the Max Date for void”);

}

In my previous code ,I had put everything separately in a variable that’s the reason the field name was changed.

Output which I should get is
IF StartDate is inbetween caestartdate and caeenddate then no validation and to accept caevoid checkbox checked value.
If startdate is not in between caestartdate and caeenddate then Validation message and should not save caevoid check box value

Please let me know if my above description is not clear.

I’m sorry, but there is nothing I can do without more information from you. Start with replacing “not working” with an actual description of your problem. Then (if needed) show us the part of code that doesn’t work as expected and tell us what are values of your variables.

Note that the debugger will help you understand what your code does. I can’t debug your code for you (even if I wanted), because you’ve shown just a piece of it.

Thanks for your response. Please don’t follow my code. I just wanted to know how to validate whether selected date is in between two other dates from another table. How to write between operator in AX.
In sql ,I used to write
If( Date 1 >= Date A) && (Date1 < = DateB)

Same way if I write in AX ,
public boolean validateWrite()
{
boolean ret;
CaePR caepr1;
PRCurrentPeriod prcurrentperiod;
date startdt;
date enddt;
startdt = str2Date(“05/01/2016”, 213);
enddt = str2Date(“05/31/2016”,213) ;

ret = super();

if(ret)
{
select maxof(caeStartDate) from caepr1 where caepr1.Worker == this.Worker && this.caeVoid==0;
if(this.caeVoid == 0)
{
If (this.caeStartDate < caepr1.caeStartDate)
{
ret = ret && checkFailed(“Please select the Max Date”);
}
}

if (this.caevoid==1)
{
if((this.caeStartDate >= startdt)&&(this.caestartdate<=enddt))
{
ret = ret && checkFailed(“Please select the Max Date for void”);
}
}
}
return ret;
}

Compilation was successful. When I click on the check box caevoid for the selected date which is NOT inbetween two dates, Still it doesn’t give any validation message.
Data as follows
CAEPr
caestartdate = 04/29/2016
CAEVoid = 1
When the user selects April 29 which is not in between May1st and May 31 and selects caevoid check box, on closing the screen it accepts. But actually it should throw validation message saying "Please select the Max Date for void
For testing purpose I have put the 2 dates hardcoded inside a variable rather than pulling from another table.

With the debug option I have an issue with my system. That’s the reason am not able to check.
I hope my description would b more precise that before. If not let me know.

Thanks

HI,

I think below code will work for you.Please try and provide your updates to the forum

public static boolean ValidateStartDateEndDate(FromDate startDate, ToDate endDate)
{
if(startDate != mkDate(1,1,1900) && endDate != mkDate(1,1,1900) && (startDate && startDate > endDate))
return checkFailed("@SYS120590");
else if(startDate && startDate == endDate)
return true;
else
return true;
}

Mahesh

public static boolean ValidateStartDateEndDate(FromDate startDate, ToDate endDate)
{
if(startDate != mkDate(1,1,1900) && endDate != mkDate(1,1,1900) && (startDate && startDate > endDate))
return checkFailed(“From date cannot be greater than to date”);
else if(startDate && startDate == endDate)
return true;
else
return true;
}

Mahesh