cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ralfie234
New Member

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

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Did you miss the call? Check out the recording here!

Top Solution Authors
Top Kudoed Authors
Users online (37,171)