cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ralfie234
Frequent Visitor

Form validation displaying error message even when valid

Hi

 

I have customised a Sharepoint form using power apps, in the OnSave event I am doing a check, if all good submit, if not display an error.

 

- If there are validation issues it works correctly, doesnt submit the form & displays the error

 

- If there are no validation issues, it submits the form BUT STILL displays the error message

 

I have tried lots of different ways but always the the same behaviour, a valid submission looks like:

 

ralfie234_0-1612434402409.png

 

My OnSave event looks like:

 

Set(varApprovalStatus, "Pending"); Set(varCreateTotalSelectCount, VarContractSelectCount + VarTermSelectCount + VarApproverSelectCount); Set(varEditTotalSelectCount, VarEdiTermSelectCount + VarEditApproverSelectCount);

 

 

If(SharePointFormMode="CreateForm" And varCreateTotalSelectCount=3, SubmitForm(TerminationsSPFormNew), Notify("Check required fields",NotificationType.Error));

 

If(SharePointFormMode="EditForm" And varEditTotalSelectCount=2, SubmitForm(TerminationsSPFormEdit), Notify("Check required fields",NotificationType.Error));

 

 

 

Any idea why my Error message displays regardless of if the validation is true or false?

1 ACCEPTED SOLUTION

Accepted Solutions
Slaverty
Advocate III
Advocate III

Hey,

Have you nested those If statements?  If not, I think that'll be what's causing it.

On a "CreateForm", if it matches the criteria then the first If statement will submit the form, but then the second If statement will return "false" as it's not an EditForm but a CreateForm.  

You need to do some nesting so that the form will only be interrogate against one of those IF statements

View solution in original post

5 REPLIES 5
JR-BejeweledOne
Super User
Super User

I don't know if this is causing your error, but there is no FormMode called CreateForm unless this is something you have set somewhere.

 

The valid form Modes are New, Edit and Display.



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.

Oh yeah sorry should have said, I have a Var setup called SharePointFormMode to record the form mode, sorry 🙂

Slaverty
Advocate III
Advocate III

Hey,

Have you nested those If statements?  If not, I think that'll be what's causing it.

On a "CreateForm", if it matches the criteria then the first If statement will submit the form, but then the second If statement will return "false" as it's not an EditForm but a CreateForm.  

You need to do some nesting so that the form will only be interrogate against one of those IF statements

View solution in original post

Fixed, swapped the ; for a , and all good:

 

Set(varApprovalStatus, "Pending"); Set(varCreateTotalSelectCount, VarContractSelectCount + VarTermSelectCount + VarApproverSelectCount); Set(varEditTotalSelectCount, VarEdiTermSelectCount + VarEditApproverSelectCount);

 

 

If(SharePointFormMode="CreateForm" And varCreateTotalSelectCount=3, SubmitForm(TerminationsSPFormNew), Notify("Check required fields",NotificationType.Error),

 

If(SharePointFormMode="EditForm" And varEditTotalSelectCount=2, SubmitForm(TerminationsSPFormEdit), Notify("Check required fields",NotificationType.Error)));

 

Thanks

Slaverty
Advocate III
Advocate III

Ah, swapped the ; for , and moved a bracket, took me a minute to spot that heh.  Unfortunately I think that solution might only work for new forms.  I believe you'll need a formula more like this.

 

If(
    SharePointFormMode="CreateForm",
    If(
        varCreateTotalSelectCount=3, SubmitForm(TerminationsSPFormNew), Notify("Check required fields",NotificationType.Error)),
    If(
        varEditTotalSelectCount=2, SubmitForm(TerminationsSPFormEdit), Notify("Check required fields",NotificationType.Error))
);

 

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (1,487)