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

Error Handling - Desktop application Error Message Dialog Box

Hi there, 

 

I have a Power Automate Desktop flow that reads data from a CSV file (source) where each row consists of 4 columns.

 

It then opens a Desktop Application and uses a "for each" loop to populate text fields in the application and presses the "OK" button to submit the data. That all works well if the data is valid.

 

My problem is I cannot seem to capture Desktop application error messages on screen if they appear, is there a way to do this?

 

Valid data meaning datatypes are correct for each field (whole number, text field, date etc.) and numbers are not negative or too large, if so, the Desktop application produces an error message on screen with details of the error.

 

The Desktop application could also produce an error after all 4 fields and been filled in, the "OK" button is pressed but the data is not valid, example the project number does not exist etc. 

 

So there are multiple different error messages that may appear, depending on what triggered it. The error message dialog box appears approximately in the same position on the screen each time regardless of what the error is. That is, if the position of the error message box could be used to determine if an error occurred, that might work.

 

Each CSV file consists of 100+ rows, ideally I want the flow to enter them one-by-one and if a Desktop application error appears on screen, the row gets written to an CSV error log file and continues the loop to the next row until finished.

 

Have tried surrounding the process in a "On Block error" but that does not capture the error message that may or may not appear on screen.

 

My guess is that somehow I need to use an "If" statement on the error message dialog box, so that if an error message appears, than write to log file, else proceed to next row. But haven't been able to figure it out the logic so far...

 

Any help would be much appreciated.

Thanks

Nick

2 ACCEPTED SOLUTIONS

Accepted Solutions
amamidwar23
Helper I
Helper I

Hi NIck,

Your guess is correct!!

you need to check for some kind of selectors that signifies whether the transaction is successful or failed using the if statement.

 

1) set a  variable(Status) and flag it true/false based on successful/failure activity, inside if statement, or on block error action.

 

2) then based on a variable (status) value, use the next loop action to skip that iteration and go for the next row (you can use label/goto action )

 

Hope this helps !!

Regards,

 

AR

 

View solution in original post

aminab-msft
Microsoft
Microsoft

Hello

 

thank you for the detailed write-up. Have you tried the "If Window Contains" block?

Here are the steps you need to take:

1. create the circumstances that make the app throw the error

2. capture the UI element that consists of that error message dialog

3. in your desktop flow, drop the "If Window Contains" block

4. inside the If Window Contains block, add your logic to write to the log file the data from the CSV that didn't get written to the app

 

aminabmsft_1-1624370555103.png

to reach the error message dialog, you can either capture the UI element by going to the UI elements pane > Add UI element > reproducing circumstances of errors > Ctrl-Click on the error message dialog when it appears

 

hope this helps, let us know if it doesn't!

 

Best,

Amina

 

 

 

 

View solution in original post

5 REPLIES 5
amamidwar23
Helper I
Helper I

Hi NIck,

Your guess is correct!!

you need to check for some kind of selectors that signifies whether the transaction is successful or failed using the if statement.

 

1) set a  variable(Status) and flag it true/false based on successful/failure activity, inside if statement, or on block error action.

 

2) then based on a variable (status) value, use the next loop action to skip that iteration and go for the next row (you can use label/goto action )

 

Hope this helps !!

Regards,

 

AR

 

View solution in original post

AshleyPettit
Frequent Visitor

Hey Nick,


I wrote my own error logging as I find it better for me. For your situation you potentially are most interested in the take a screenshot function. Capture a screenshot when the error occurs.

 

Also use "Get Last Error" and use that to create your own error log in notepad. 

 

If you like I can email you a screenshot of what I use in the desktop client. 

 

Below looks pretty hard to understand but I can't find a nice way to copy it in here. 

 

What I'm doing here is taking the error and saving it into a notepad document. I'm also taking a screenshot of the screen when the error occured. This keeps a nice log of the time the error occured and what it was doing when it errored. 

 

I use a block rescue and the block rescue calls the subflow "ErrorHandle". 

 

Lastly the program is retrying the whole action under a block error 3 times. If it fails more than 3 times it will discount the row; mark error and message me via email that the row failed. It will then try the next row. 

 

 

ERROR => LastError


Variables.IncreaseVariable Value: ErrorThreeTimesOnSameCandidate IncrementValue: 1 IncreasedValue=> ErrorThreeTimesOnSameCandidate


Variables.IncreaseVariable Value: ErrorCount IncrementValue: 1 IncreasedValue=> ErrorCount
File.WriteText File: $'''%PathToDesktop%\\PowerAutomateBkgCheck\\Errors.txt''' TextToWrite: $'''%ErrorCount%.%ErrorThreeTimesOnSameCandidate% | %CurrentDateTime% | %LastError% | RecentError -> %RecentError% | Last search request -> %SearchingFor%''' AppendNewLine: True IfFileExists: File.IfFileExists.Append Encoding: File.FileEncoding.Unicode

 

ON ERROR

END

 

DISABLE System.TakeScreenshotOfForegroundWindowAndSaveToFile File:

 

$'''%PathToDesktop%\\PowerAutomateBkgCheck\\Errors\\%PersonError%.jpg''' ImageFormat: System.ImageFormat.Jpg


Display.ShowMessageWithTimeout Title: $'''Please don\'t touch while I\'m running!''' Message: $'''Please don\'t touch while I\'m running!

 

Restarting - Press cancel to stop

An unexpected error occured - %RecentError%

LAST SEARCH REQUEST (OCR) -> %SearchingFor%

Standard Error Message -> %LastError%

This candidate will error out if 3 errors occur. %ErrorThreeTimesOnSameCandidate% out of 3.''' Icon: Display.Icon.None Buttons: Display.Buttons.OKCancel DefaultButton: Display.DefaultButton.Button1 IsTopMost: True Timeout: 5 ButtonPressed=> ErrorButtonPressed
IF ErrorButtonPressed = $'''Cancel''' THEN
System.TerminateProcessByName ProcessName: $'''excel'''
EXIT Code: 0
END
IF ErrorThreeTimesOnSameCandidate >= 3 THEN
IF PersonError = $'''NotYetSet''' THEN
Outlook.SendEmail Instance: OutlookInstance Account: $'''a.pettit@unsw.edu.au''' SendTo: $'''a.pettit@unsw.edu.au''' Subject: $'''Check Background Check Upload - Critical Bookup Error''' Body: $'''Check Background Check Upload - Critical Bookup Error. %ErrorCount%-%ErrorThreeTimesOnSameCandidate% %DateUNSWFormat% %LastError% | RecentError -> %RecentError% | Last search request -> %SearchingFor% | Last Document Type = %DocumentType% | Person -> %PersonError%''' IsBodyHtml: False
EXIT Code: 0 ErrorMessage: $'''Critical Bootup Error'''
END
IF Task = $'''Fit2WorkDownload''' THEN
IF ErrorThreeTimesOnSameCandidate >= 5 THEN
Excel.WriteCell Instance: ExcelInstance Value: $'''CANCELLED''' Column: 16 Row: PeopleProcessedCount + 2
ELSE
Excel.WriteCell Instance: ExcelInstance Value: $'''ERROR - Failed three times on same person.''' Column: 16 Row: PeopleProcessedCount + 2
END
ELSE IF Task = $'''PageUpUpload''' THEN
Excel.WriteCell Instance: ExcelInstance Value: $'''ERROR - Upload Fail - Failed three times on same person.''' Column: 15 Row: PeopleProcessedCount + 2
END
Variables.IncreaseVariable Value: UnprocessedApplicants IncrementValue: 1 IncreasedValue=> UnprocessedApplicants
SET ErrorThreeTimesOnSameCandidate TO 0
END
Excel.Save Instance: ExcelInstance
ON ERROR

END

aminab-msft
Microsoft
Microsoft

Hello

 

thank you for the detailed write-up. Have you tried the "If Window Contains" block?

Here are the steps you need to take:

1. create the circumstances that make the app throw the error

2. capture the UI element that consists of that error message dialog

3. in your desktop flow, drop the "If Window Contains" block

4. inside the If Window Contains block, add your logic to write to the log file the data from the CSV that didn't get written to the app

 

aminabmsft_1-1624370555103.png

to reach the error message dialog, you can either capture the UI element by going to the UI elements pane > Add UI element > reproducing circumstances of errors > Ctrl-Click on the error message dialog when it appears

 

hope this helps, let us know if it doesn't!

 

Best,

Amina

 

 

 

 

View solution in original post

Hi @AshleyPettit, thank you for the detailed response. I will try that out. As you said its not so easy to follow in text form. But the description of the logic makes sense, so I'll see if I can use it. Thanks! 😊

Thank you @aminab-msft, That makes sense, will give that try. I have got it working now after a lot of blood sweat and tears. I am dealing with an old custom legacy desktop app, hence the reason PAD was not capturing/seeing the modal dialog error message. I did a simple flow, focused on producing the error and used breakpoints to step through the error message. I used 'Get details of window' to check if any text from the error message captured, and if so triggered the error handling sub flow, which works.

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

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.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Top Solution Authors
Users online (1,167)