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

Triggering a flow in OnFailure property of a submitted form

In my app there is an Edit form which writes to a sharepoint list. There is a flow that handles a number of notifications off the back of a submission, so generally this is triggered in the OnSuccess property and works just fine. I also want the same flow to trigger in the OnFailure properly passing the form.error object as a context variable to the flow.

 

So, much like in the OnSuccess property I have this code in the OnFailure:

 

NameofmyFlow.Run("ERROR",detailsEditForm.LastSubmit.ID,User().FullName,User().Email,detailsEditForm.Error);UpdateContext({showPopup:false}); Notify("There was an error submitting the form. A helpdesk ticket has been raised", NotificationType.Error)

 

When the form errors I see the Notify message and the 'showPopup' variable is changed to close my dialog box but there is no evidence of the flow being triggered in Power Automate. Nor any errors being returned to indicate why. The exact same (except the first context string isn't "ERROR") Flow.run works in OnSuccess

4 REPLIES 4
Community Support
Community Support

Hi @WillJay ,

Is there some error message with the NameofmyFlow.Run() formula within the OnFailure property of the Edit form?

 

Based on the issue that you mentioned, I found that the OnFailure property of the Edit form has been fired successfully. Please check if there is an error message with your NameofmyFlow.Run() formula.

 

According to the formula that you provided, I could not find any syntax error with it. I have also made a test on my side, and do not have the issue that you mentioned, the flow fires well on my side.

 

Please also consider take a try with the following workaround:

Set the OnSelect property of the "Submit" button to following:

If(
   detailsEditForm.Valid,
   SubmitForm(detailsEditForm),
  NameofmyFlow.Run("ERROR",detailsEditForm.LastSubmit.ID,User().FullName,User().Email,detailsEditForm.Error);UpdateContext({showPopup:false}); Notify("There was an error submitting the form. A helpdesk ticket has been raised", NotificationType.Error)
)

Note: Please remove the formula from the OnFailure property of the Edit form

Please take a try with above solution, check if the NameofmyFlow.Run() formula could be fired successfully

 

In addition, there may have some delay in firing the flow from your canvas app, please wait for 1 minute almost, then refresh the Flow Run History, then check if the flow is exected.

 

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

Thanks @v-xida-msft ,

 

I gave that a try, however it is database operation errors I want to catch rather than form validation. As such the formula you've written will attempt to submit the form and fail (I'm deleting the target list record for my test case) which is what I believe OnFailure should pick up. Is that what you have managed to get working with your attempt?

 

I think you're on the right lines, I can probably do some sort of try....catch error handling on the submit button where I kick off the form submission I suppose....It just seems so strange that the OnSuccess property of the same form successfully triggers the Flow, the OnFailure property does not. I might also try creating a separate Flow just for the error.

Hi @WillJay ,

Yeah, the flow fires well within the OnFailure property of my Edit form. I agree with your thought almost. You could consider create another separated flow to handle the error event, then execute another flow action within the OnFailure property of Edit form, check if the issue is solved.

 

In addition, as an alternative solution, you could consider set the OnSelect property of the "Submit" button to following:

SubmitForm(EditForm1);
If(
    !IsEmpty(Errors('Your SP List')),
    NameofmyFlow.Run("ERROR",detailsEditForm.LastSubmit.ID,User().FullName,User().Email,detailsEditForm.Error);UpdateContext({showPopup:false}); Notify("There was an error submitting the form. A helpdesk ticket has been raised", NotificationType.Error)
)

 

or

Set the OnSelect property of the "Submit" button to following:

SubmitForm(EditForm1);

set the OnFailure property of the Edit form to following:

If(
    !IsEmpty(Errors('Your SP List')),
    NameofmyFlow.Run("ERROR",detailsEditForm.LastSubmit.ID,User().FullName,User().Email,detailsEditForm.Error);UpdateContext({showPopup:false}); Notify("There was an error submitting the form. A helpdesk ticket has been raised", NotificationType.Error)
)

 

Please take a try with above solution, check if the issue is solved.

 

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

I have to admit I didn't realise that a run error would only be visible in the actual code bar and that certain other actions would clear it. In attempting your solutions (which would probably work!) I learnt this and discovered the issue all along has been that I've been trying to pass an integer to the flow using formname.LastSubmit.ID - however if a submission fails (at least for the failures I've been testing) then .LastSubmit doesn't contain a record. 

 

I replaced the LastSubmit.ID with a hardcoded integer value and the original code worked!

 

Thanks for the help 🙂

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 (4,099)