Changing the state of the dynamic panel inside a repeater dynamically based on the number of days between the date in the repeater dataset and the current date

tips-and-tricks

#1

Let’s say you’d like to change the state of the dynamic panel in your repeater dynamically based on the number of days between today’s date and the date in the repeater column. It can look like this:

I will explain below in detail how to achieve this behavior:

The widget setup.

The widgets I list below are all under the repeater " Repeater_table ". There are two rectangles connected to the repeater dataset:

the first, " Name Re ," serves to store the customer name,

the second, " First_Contact_Date_Re ," stores the date values.

There is also a dynamic panel, " Status_Dynamic Panel ," to set the status of the call. Within this dynamic panel, you can see two states: Red with the “Red_Re” box --to show the status if the repeater date is further than 60 days from the current date, and Green with the “Green_Re” box --to show the status if the repeater date is closer or equal to 60 days.

The third rectangle, " VariableValue_Re ," shows the variable’s value for the number of days between the current date and the date in the repeater.

There is also one global variable, " DaysNumber " ((Project>Global variables), to store the number of days between the current date and the dates in the repeater dataset.

All action happens under the “Item Loaded” interaction of the repeater widget.

The first condition, “Always true”, fires whenever the repeater dataset is loaded. Inside it, the variable “DaysNumber” is set to [[Math.floor((Date.Parse(Now)-Date.Parse(Item.ColumnStartDate))/1000/60/60/24)]]. This formula uses Date.Parse() to return the difference between the current date and the repeater date in milliseconds, then the [[/1000/60/60/24]] part converts it into days and Math.Floor() rounds the value down.

Then, we set the text in the “VariableValue_Re” to the value of this variable.

The second condition, “It’s more than 60 days”, compares the value of the variable with the number “60”, and if the value of the variable is greater, then the state of the dynamic panel is set to “Red”, and the text on the rectangle inside of this state is set to “It’s been more than 60 days–[[DaysNumber]] to be exact! We lost this client!”.

The third condition, “If it’s less or equal to 60”, runs if the else is true. Then, the dynamic panel is set to its “Green” state, and the text on the rectangle inside this state is set to “It’s been less than 60 days–[[DaysNumber]] to be exact! We should call this client!”.

You can see it in action here: https://6a0pk1.axshare.com/, and here is a copy of my .rp file NumberOfDays.rp (67.5 KB). I hope you find it helpful in your future projects!