Hi everyone!
I need to prevent users from submitting a form (SharePointIntegration) where the "End Date" (DataCardValue7) is earlier than the "Start Date" (DataCardValue6). Both are date pickers.
Currently, I've added the following expression to the "OnChange" property of DataCardValue7:
If (
DataCardValue7.SelectedDate < DataCardValue6.SelectedDate,
Set(varError, "The end date cannot be earlier than the start date.");
Notify(
varError,
NotificationType.Error,
5000
),
DataCardValue7.SelectedDate >= DataCardValue6.SelectedDate,
Set(varError,"")
)
The issue is that users can still submit the form because it doesn't have an "OnSave" property where I can add code to control submission based on date errors. What can I do to prevent form submission with invalid dates?
Thank you in advance for any help you can provide.
Hi @WarrenBelz
Starting from the fact that I am a novice with programming and with Power Automate, I had forgotten that the SharePointIntegration object had the OnNew, OnSave, etc. events... my bad...
In the end, I added a condition in the OnSave event that controls both date pickers.
Thank you very much for your help!
Hi @FlowFalcon ,
I assumed from your post that OnSave was not working for you (which often happens) hence the alternative. In answer to your second question, put it in a Label above the Form instead of in the Form.
Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.
MVP (Business Applications) Visit my blog Practical Power Apps
Hey,
Instead of resetting Self, reset either DataCardValue7 or DataCardValue6, depending on where you are adding the code.
Hi @WarrenBelz
Thank you so much for your willingness to help!
I had already tried the code you sent me, but the Reset(Self) function doesn't clear the value of the date picker.
I understand that in Power Apps, you can't reset and leave it blank (I might be wrong, as I'm a novice).
Additionally, I didn't realize that the "OnSave" property was available in "SharePointIntegration", so I added the following:
If(
DataCardValue7.SelectedDate >= DataCardValue6.SelectedDate,
SubmitForm(SharePointForm1),
Notify("ERROR: End date cannot be earlier than start date.", NotificationType.Error)
)
Since we're here, can I ask you another question, or should I open a new topic? It's about the form header (Vacation Header) —I need it to remain fixed and not disappear when scrolling. Is this possible with SharePointIntegration forms?
Thank you very much in advance.
Hi @FlowFalcon ,
Make the Required property of the Data Card true, then OnChange of DataCardValue7 put
If(
Self.SelectedDate < DataCardValue6.SelectedDate,
Notify(
"End Day cannot be before Start Day",
NotificationType.Error
);
Reset(Self)
)
If the date is before, it will clear the value and as it is a required field, will not allow submission of the Form.
Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.
MVP (Business Applications) Visit my blog Practical Power Apps
Hey @FlowFalcon
Just put the code control in your submit button with an If Statement. If it's not okay don't save it. You could even Block the button from being clickable if the end Date it smaller than start Date.
WarrenBelz
146,524
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,906
Most Valuable Professional