cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Sifu
Post Prodigy
Post Prodigy

Prevent user from submitting SPO form if not all fields entered

Hello everyone,

 

I am doing a form where user should fill in all data but it seems that what (i think) should work is not working as expected.... the code below is assigned to the submit button (onselect) but if user would visit the list it self he could still bypass it with the save button... any idea how to prevent that?

 

//validation starts here
If(And(
//is the date free?
    If(checkresult.Text = "not ok", false, true),
//do you have enough holiday and do we wory about that?
    If(((Value(value_selected_days.Text) > value_available_days.Selected.RestVacationDays) And value_over_limit.SelectedText.Value="No"), false, true), 
//are you trying to book more days in advance then we allow you to?
    Not(If(DateDiff(Today(), todate.SelectedDate) > 30,true,false))
    ),
//if above is true it will create a variable like below:
    Set(validationCheck,true),
    Set(validationCheck,false)
);
//the actual collect if validation variable is true:
If(
    validationCheck=true,
//this creates a new entry in the AR LIST (Absence request)
Patch(AR,Defaults(AR),{From:fromdate.SelectedDate,To:todate.SelectedDate,TypeOfRequest:"Holiday",AvailableVacationDays:value_available_days.Selected.RestVacationDays,RequestedVacationDays:Value(value_selected_days.Text),NewVacationDays:Value(value_available_days_new.Text),UPN:'upn-label_1'.Text});

//this updates the vacation status (substracts days) in the HR Settings list, right after the request ist placed
Patch(HR_settings,LookUp(HR_settings, UPN = 'upn-label_1'.Text),{RestVacationDays:Value(value_available_days_new.Text)});

//this udpates the column Status in table TNA to "Set"
UpdateIf(tna, (UPN = 'upn-label_1'.Text And DateInNr >= Value(fromdatenr.Text) And DateInNr <= Value(todatenr.Text)), {Status: "Set" });

//other required parameter so it will show sucsess is navigate to success screen
Navigate( Success, ScreenTransition.CoverRight ),

//else value starts here, if not all fields are filled
Navigate( 'FormHoliday-Error', ScreenTransition.CoverRight )
);

  

1 ACCEPTED SOLUTION

Accepted Solutions
v-xida-msft
Community Support
Community Support

Hi @Sifu ,

Do you customize a form app in your SP List using Power Apps?

Do you add a additional "Submit" button in your custom form screen to submit form data?

 

If you want the validation formula to be worked as expected when you click the "Save" button in your custom form app, please try the following workaround:

Set the OnSave property of the SharePointIntegration control in your custom form app to following:

//validation starts here
If(And(
        If(checkresult.Text = "not ok", false, true),
        If(
           Value(value_selected_days.Text) > value_available_days.Selected.RestVacationDays && value_over_limit.SelectedText.Value="No", false, true
        ), 
        Not(If(DateDiff(Today(), todate.SelectedDate) > 30,true,false))
    ),
    Set(validationCheck,true),
    Set(validationCheck,false)
);
If(
    validationCheck=true,
    Patch(
          AR,
          Defaults(AR), 
{From:fromdate.SelectedDate,To:todate.SelectedDate,TypeOfRequest:"Holiday",AvailableVacationDays:value_available_days.Selected.RestVacationDays,RequestedVacationDays:Value(value_selected_days.Text),NewVacationDays:Value(value_available_days_new.Text),UPN:'upn-label_1'.Text});
Patch(HR_settings,LookUp(HR_settings, UPN = 'upn-label_1'.Text),{RestVacationDays:Value(value_available_days_new.Text)});

//this udpates the column Status in table TNA to "Set"
UpdateIf(tna, (UPN = 'upn-label_1'.Text And DateInNr >= Value(fromdatenr.Text) And DateInNr <= Value(todatenr.Text)), {Status: "Set" });

//other required parameter so it will show sucsess is navigate to success screen
Navigate( Success, ScreenTransition.CoverRight ),

//else value starts here, if not all fields are filled
Navigate( 'FormHoliday-Error', ScreenTransition.CoverRight )
);

 

Please try above solution, then check if the issue is solved.

 

Regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

8 REPLIES 8
Pstork1
Dual Super User
Dual Super User

Rather than a long complex formula I've normally done this by adding code to each control's onChange property to increment a counter if the value is not empty and decrement if it is.  Then put a simple IF() in your display mode for the submit button.  Disable the button if the counter is greater than or equal to the number of controls on the page.  You have to add things in a lot of places, but its much simpler to maintain.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

@Pstork1  thanks for info, but i am not getting how this will prevent users from selecting the save button

 

Sifu_0-1596819976312.png

 

Pstork1
Dual Super User
Dual Super User

Sorry, I didn't know you were talking about an integrated form.  For that you can put something in the OnSave event that will keep the form from being submitted.  I'm not aware of any way to disable the built-in menu entry.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
BrianS
Super User
Super User

If you do not want people interacting with the list you can create a view with no entries (ID=0) and then not allow others to create views. You can also keep the list from showing up in searches through a control in the list settings. 

Pstork1
Dual Super User
Dual Super User

You can't keep people from making their own private views of a list in SharePoint online.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.
dyee4614
Helper V
Helper V

Ignore this.

you could stop them if you give them access only for "add only" and create a view which you find ok, ...this however does not solve the problem, i will test the on save feature on monday

v-xida-msft
Community Support
Community Support

Hi @Sifu ,

Do you customize a form app in your SP List using Power Apps?

Do you add a additional "Submit" button in your custom form screen to submit form data?

 

If you want the validation formula to be worked as expected when you click the "Save" button in your custom form app, please try the following workaround:

Set the OnSave property of the SharePointIntegration control in your custom form app to following:

//validation starts here
If(And(
        If(checkresult.Text = "not ok", false, true),
        If(
           Value(value_selected_days.Text) > value_available_days.Selected.RestVacationDays && value_over_limit.SelectedText.Value="No", false, true
        ), 
        Not(If(DateDiff(Today(), todate.SelectedDate) > 30,true,false))
    ),
    Set(validationCheck,true),
    Set(validationCheck,false)
);
If(
    validationCheck=true,
    Patch(
          AR,
          Defaults(AR), 
{From:fromdate.SelectedDate,To:todate.SelectedDate,TypeOfRequest:"Holiday",AvailableVacationDays:value_available_days.Selected.RestVacationDays,RequestedVacationDays:Value(value_selected_days.Text),NewVacationDays:Value(value_available_days_new.Text),UPN:'upn-label_1'.Text});
Patch(HR_settings,LookUp(HR_settings, UPN = 'upn-label_1'.Text),{RestVacationDays:Value(value_available_days_new.Text)});

//this udpates the column Status in table TNA to "Set"
UpdateIf(tna, (UPN = 'upn-label_1'.Text And DateInNr >= Value(fromdatenr.Text) And DateInNr <= Value(todatenr.Text)), {Status: "Set" });

//other required parameter so it will show sucsess is navigate to success screen
Navigate( Success, ScreenTransition.CoverRight ),

//else value starts here, if not all fields are filled
Navigate( 'FormHoliday-Error', ScreenTransition.CoverRight )
);

 

Please try above solution, then check if the issue is solved.

 

Regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (1,786)