cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Resolver III
Resolver III

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
Highlighted

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
Highlighted
Dual Super User III
Dual Super User III

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.
Highlighted

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

 

Sifu_0-1596819976312.png

 

Highlighted
Dual Super User III
Dual Super User III

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.
Highlighted
Responsive Resident
Responsive Resident

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. 

Highlighted
Dual Super User III
Dual Super User III

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.
Highlighted
Helper V
Helper V

Ignore this.

Highlighted

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

Highlighted

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

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (11,215)