I need to create an expiration date for a BO based on child records for that BO that have a 'Expires in Years' type attribute.
Here is what I have:
Parent BO (Event): Has a attribute called LastExpirationDate and one called "EventDate"
Child BO (Reasons): Multiple records that have atrributes called "Reason" and "ExpiresInYears"
Whenever an Event is saved I have a rule that checks to see if there are any Reason records for that Event. If there are I want to update the Event LastExpirationDate with (EventDate + ExpiresInYears - 1 Day). But I really only want to update it with the largest ExpiresInYears value.
So, if I have 5 records in the Reasons BO and they have expiration values of 1,2, 3, 4, & 5; I really only want the last one to be used to update the LastExpirationDate attribute.
Does that make sense?
Right now I have it read through each Reason record, sorted by the Expiration value and update the LastExpirationDate everytime, hoping that the last one is the one I actually want. My rule looks like the following:
If Event.child_Reasons IS DEFINED Then
FIND Event_Reasons WHERE Event_Reasons.Event=Event AND Event_Reasons.ExipresInYears>0 ORDER BY Event_Reasons.ExpiresInYear ASC
Event.LastExpirationDate=AS_DATE(AS_STRING(DAY_OF_MONTH(Event.EventDate)-1)+'-'+AS_STRING(MONTH(Event.EventDate))+'-'+AS_STRING(YEAR(Event.EventDate)+Event_Reason.ExipresInYears),'dd-MM-yyyy')
The actual calculation of the ExpirationDate works fine. It is the order of the records that seems to be an issue. It is inconsistent.
I am sure there is an easier way to do this, but not sure what it is yet.
Any ideas?