Hi there,
I am wondering when create new attribute in an aggregate:
If i take out the expression:
and AgingReport_D.FinalExpireddate <= AddMonths(CurrDate(),1)
it is correct.
If i use other function, it is correct as well:
If(DiffDays(CurrDate(),AgingReport_D.FinalExpireddate) >= 0 and DiffDays(CurrDate(),AgingReport_D.FinalExpireddate) <= 30,1,2)
But this works:
AgingReport_D.FinalExpireddate >= CurrDate() and AgingReport_D.FinalExpireddate <= DateTimeToDate(AddMonths(CurrDate(),1))
--- so it is <= date vs datetime..i ll try later,,,thanks
Why is it error - AddMonths ? thanks
I would add to Paulo's response a suggestion to use DateTimeToDate conversion instead of DateToDateTime to avoid possible errors for edge dates. For instance, DateToDateTime(test.EndDate) >= CurrDateTime() is false when EndDate is today and it is not exactly midnight. So the expression will look like this:
If(test.EndDate >= CurrDate() and test.EndDate <= DateTimeToDate(AddMonths(CurrDateTime(),1)),1,2)
Hello Indra,
The issue has to do with the type of variables that you are using.
AddMonths() returns a valid DateTime so to be able to use it in this scenario you have to make sure that the date that you are using to compare to that new one ( AgingReport_D.FinalExpireddate ) is also of the type DateTime and not only Date.
You can achieve this in a couple of ways:
In this example, test-EndDate is of type DateTime.
If ( test.EndDate >= CurrDateTime() and test.EndDate <= AddMonths(CurrDateTime(),1),1,2)
In this example, EndDate is of type Date.
If ( DateToDateTime(test.EndDate) >= CurrDateTime() and DateToDateTime(test.EndDate) <= AddMonths(CurrDateTime(),1),1,2).
Hope it helps!
Paulo Rosário
Thank U very much Guru Paulo and Darina,
u rock!
Glad I could help :)
In an addition to the above, yeah, this is just very unhelpful of Service Studio. When you just compare a Date and a Date Time, it gives a useful error:
but as soon as you add an If, it defaults to the error you experienced:
You could report this to OutSystems via the Feedback button in Service Studio: