Top

Read SAP status bar MessageType from Power Automate Desktop


When you build RPA to handle processes in SAP, it is a good practice to check what status bar displays every time bot confirms data inserted on a screen or tries to navigate away from it. Just to be sure, there is no warning or error message, that should be handled by a bot.

ABAP status bar messages are usually a plain text supplemented with the icon that shows its type. When you double click it you get its details. Message always has its Class and Number (like in example below: F and 2164). There are hundreds of these messages: https://www.sapdatasheet.org/abap/msag/.

Basically, SAP UI does not deliver any kind of information that could let you precisely tell, that there’s an error or not. In the beginning I was trying to simply check, if status bar contains icon that is either error or warning by using “If image” condition and captured images:

However this approach was somehow not really working. I was trying to set different Tolerances, but if it was too high – rule was always true. For you to know – value can be between 1 and 256. If to low – never true. I was stuck.

Visual Basic Script to the rescue!

I started searching how to read that status message type. This way I acknowledged, that actually this plain text message has its types:

  • A : ( Shows the errors without resuming the program execution )
  • E : Error Messages ( Shows the errors and current program execution will be terminated )
  • I : Informational Messages ( Just displaying the information and can be avoided )
  • S : Success Messages ( On next screen for showing successful process completion message )
  • W : Warning Messages ( Displaying the errors that can be ignored )
  • X : Exit messages ( Immediate termination of the program and shows system dump error messages )

Following ABAP MESSAGE Statement and types – SAP Stack

Once I found it, I started looking at possible ways for retrieving them. The only way I found actually was to use Visual Basic Script. Since I am not a developer, I spent some time on figuring out how to write that script, but I am more than happy to share it with you. Simply copy and paste it into “Run VBScript” action in Power Automate Desktop:

Set SapGuiAuto = GetObject ("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
Set connection = application.Children(0)
Set session = connection.Children(0)
   
WScript.Echo session.findById("wnd[0]/sbar").MessageType

You can use “MessageType” to get A, E, I, S, W or X letters. Or you can use “Text” to simply retrieve what is displayed in status bar.

Also, I used then action Trim, because VBS Trim somehow didn’t work for me and returned value was always supplemented with whitespace and empty line. This is how it looks at my side:

Do you find it useful? Leave me a comment! 🙂


Tomasz Poszytek

Hi, I am Tomasz. I am expert in the field of process automation and business solutions' building using Power Platform. I am Microsoft MVP and Nintex vTE.

8 Comments
  • Egbert

    Tomasz, is User Scripting needed to be enabled for this VBScript to work?

    March 15, 2021 at 2:05 pm Reply
    • Tomasz Poszytek

      I haven’t tried it without user scripting, but per my knowledge yes – any way of accessing SAP GUI that reads UI elements requires user scripting enabled.

      March 15, 2021 at 2:15 pm Reply
  • Binta Deena Chacko

    Hi Tomasz, I’m using SAP B! along with SAP HANA. I want to automate the Sales Order form . Is it possible to do ui scripting in SAP business one?
    Thanks,
    Binta

    August 9, 2021 at 9:59 am Reply
    • Tomasz Poszytek

      Hi, I think there shouldn’t be a problem. Just be sure that gui scripting is enabled.

      August 30, 2021 at 9:39 am Reply
  • sapb1consultant

    Hi, I am developing SAP Business One HANA for chemical Industry. i am getting an exceptional error in closing production order. How can I resolve.
    Thanks!
    Shan

    April 15, 2022 at 7:49 am Reply
    • Tomasz Poszytek

      Sorry, I can’t help with that. I am not SAP consultant.

      April 15, 2022 at 5:40 pm Reply
  • Mauricio Sougarret

    Thanks for your script, it worked like a charm

    October 27, 2023 at 7:22 pm Reply

Post a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.