Hello Experts,
I have a custom calendar in my canvas app where I can choose a date range. I need to add each date in the date range as a separate entry in my SharePoint List. I have a start date along with time and end date with time. I need to add each dates selected between the date range as separate items in SharePoint list. For example, my start time would be 04/06/2021 08:00 and end time would be 06/06/2020 13:00, I want to store the dates in the following format in my SharePoint List,
DateFrom | DateTo |
04/06/2021 08:00 | 04/06/2021 13:00 |
04/06/2021 08:00 | 05/06/2021 13:00 |
06/06/2021 08:00 | 06/06/2021 13:00 |
Could anyone please help me in achieving this? Your help is greatly appreciated.
Thank you in advance!
@Anonymous
I am not entirely clear what the source of your data sample is or where it is coming from, but if you want to create a series of records in a date range, please consider the following formula:
Collect(
YourDataSource,
ForAll(Sequence(DateDiff(yourStartDate, yourEndDate, Days), 0),
{Title: "Record for " & Text(DateAdd(yourStartDate, Value), ShortDate),
DateColumn: DateAdd(yourStartDate, Value)
}
)
)
This will create how ever many records needed for the time range in your datasource.
I hope this is helpful for you.
Do it with a Timer. The timer should be set to repeat. The dteFromValue and dtToValue variable are to be set to the initial values before starting the timer.
In the OnTimerStart
Patch( SPList, Defaults( SPList ), { DateFrom: dteFromValue, DateTo: dteToValue} ) // SPList is your SharePoint List datasource
In the OnTimerEnd check if the dteToValue is less than the input ToDate if not increment both the dteFromValue variable and dteToValue by 1 day eg. UpdateContext({dteFromValue: DateAdd( dteFromValue, 1 )})
If it is greater then stop the timer by setting the variable that started it to false.
Timer control: reference - Power Apps | Microsoft Docs
Patch function - Power Apps | Microsoft Docs
DateAdd, DateDiff, and TimeZoneOffset functions - Power Apps | Microsoft Docs
Hi @JacquesOlivier ,
Thanks for the reply. When I use UpdateContext({dteFromValue: DateAdd(dteFromValue,1)}) and UpdateContext({dteToValue: DateAdd(dteToValue,1)}) in OnTimerEnd property my dteFromValue and dteToValue shows blank. I am not able to achieve my requirement. Could you please help me on this?
Thank you!
You would need to initialize the dteFromValue in the OnChange (do a UpdateContext({dteFromValue: FromField.SelectedDate}) of the from date field (e.g. DatePicker1) and set the initial dteToValue to the same date (but a different time)
@Anonymous
I'm not sure why you would use a timer for this when it is just as easy to do in one formula:
Collect(
YourDataSource,
ForAll(Sequence(DateDiff(yourStartDate, yourEndDate, Days), 0),
{Title: "Record for " & Text(DateAdd(yourStartDate, Value), ShortDate),
DateColumn: DateAdd(yourStartDate, Value)
}
)
)
Please utilize the above to simplify what you are trying to do.
User | Count |
---|---|
125 | |
87 | |
86 | |
75 | |
69 |
User | Count |
---|---|
216 | |
181 | |
140 | |
97 | |
83 |