Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Answered

Preventing SharePointIntegration Form Submission with Invalid Date Range

(1) ShareShare
ReportReport
Posted on by 102

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.


foro powerapps.jpg

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.

 

 

 

  • FlowFalcon Profile Picture
    102 on at
    Re: Preventing SharePointIntegration Form Submission with Invalid Date Range

    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!

  • Verified answer
    WarrenBelz Profile Picture
    146,524 Most Valuable Professional on at
    Re: Preventing SharePointIntegration Form Submission with Invalid Date Range

    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

     

  • SamFawzi-SmartSolutions Profile Picture
    258 Super User 2025 Season 1 on at
    Re: Preventing SharePointIntegration Form Submission with Invalid Date Range

    Hey,

     

    Instead of resetting Self, reset either DataCardValue7 or DataCardValue6, depending on where you are adding the code.

  • FlowFalcon Profile Picture
    102 on at
    Re: Preventing SharePointIntegration Form Submission with Invalid Date Range

    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.
    foro powerapps.jpg

     



  • WarrenBelz Profile Picture
    146,524 Most Valuable Professional on at
    Re: Preventing SharePointIntegration Form Submission with Invalid Date Range

    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

     

     

     

  • DBO_DV Profile Picture
    4,530 Super User 2025 Season 1 on at
    Re: Preventing SharePointIntegration Form Submission with Invalid Date Range

    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. 

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,524 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,906 Most Valuable Professional

Leaderboard