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

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

 

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. 

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

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
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Power Apps Ideas

Changes to Ideas Coming

We are excited to announce a new way to share your ideas for Power Apps!

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