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

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
Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on August 17, 2022 at 8am PDT.

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.

Users online (4,358)