Monday, March 25, 2024

Custom Power App Forms in SharePoint Online: 'Start Date and Time' and 'End Date and Time' Validation on Submit

Customizing a SharePoint list form in Power Apps and need to ensure a 'Start Date and Time' field is always earlier than its corresponding 'End Date and Time' field? See steps below. Note that I am using a Submit button for validation.

1)  Identify the data card values for your 'Start Date and Time' and 'End Date and Time' fields within your custom Power App form. The start date and time values for my solution were DateValue1HourValue1, and MinuteValue1, and the end date and time values for my solution were DateValue2, HourValue2, and MinuteValue2.

2)  Next, add a Submit button to your form. For the OnSelect property of the Submit button, enter the following If statement in the formula bar. Be sure to match the DateValue, HourValue, and MinuteValue with your data card values from Step 1.

If(DateValue2.SelectedDate + Time(Value(HourValue2.Selected.Value), Value(MinuteValue2.Selected.Value), 0) < DateValue1.SelectedDate + Time(Value(HourValue1.Selected.Value), Value(MinuteValue1.Selected.Value), 0), Notify("End Date and Time cannot be earlier than the Start Date and Time", NotificationType.Error),SubmitForm( SharePointForm1 ))

3)  Save and Publish the Power App form.