Search code examples
genexus

Recalculate the value of a variable as soon as one of the elements required to calculate it changes


I have the following problem:

I have a webpanel 'Reservations' on which the user specifies the values for a &beginDate and an &endDate (Edit).The variables &beginDate and &endDate are used as conditions for a grid.

I also have a &days variable (readonly), which is defined in rules as the difference between those two (&days=&endDate-beginDate), and its purpose is twofold:

  1. To calculate the rate of the Reservation - this works just fine

  2. To be displayed for the user. - this doesn't work as fine

My issue is that if the user updates the value of either &endDate or &beginDate the &days value isn't updated until after the grid is loaded or refreshed. I need it to change as soon as either of those.

I tried the following before looking for help:

  1. Setting notifycontextchange=true for &beginDate and &endDate and creating two TrackContext events:

`

Event TrackContext(&beginDate)
&days=&endDate-&beginDate
endevent

Event TrackContext(&endDate)
&days=&endDate-&beginDate
endevent
  1. Assign its value in start event

  2. Assign its value on a &beginDate.click and an &endDate.click Event

I already scanned these forums and found an answer that suggested using a ControlValueChanged event. The problem is that I am running Genexus X Ev1 and that event doesnt exist in here (or at least is not inherently tied to the variable).

Is there any other solution? I feel like I'm missing something truly simple :(

Im working with HTML 4.01 Transitional and a .NET environment.


Solution

  • From Genexus X EV1 upg 3 onwards you can have events that run in the browser (don't need to refresh the grid) SAC 30737.

    Try adding IsValid Events:

    Event &beginDate.IsValid
        &days = &endDate - beginDate
    EndEvent
    Event &endDate.IsValid
        &days = &endDate - beginDate
    EndEvent