Extract data from SAP GUI UI by using Power Automate - Power Automate (2024)

  • Article

When you create or update records in SAP, it generates status information which includes the newly generated record IDs. SAP displays this status information in the lower part of the SAP UI.

Here's a sample status message that SAP displays after you create an SAP PM notification.

Extract data from SAP GUI UI by using Power Automate - Power Automate (1)

This status information might be useful for the automation process steps later. Therefore you should extract and assign this status data to variables for downstream data processing.

We have multiple ways to achieve this, depending on your development approach. The two approaches are low-code or pro-code techniques.

Pro-code approach

The pro-code approach uses VBScript commands to extract information from SAP UI elements.

To extract SAP status data, such as a newly created purchase requisitions or plant maintenance notification numbers, you need access to the status bar UI element.

Here's how you access the status bar UI element.

session.findById("wnd\[0\]/sbar/pane\[0\]").Text

Let's walk through the end-to-end experience. We'll record how to create an SAP PM Notification and modify the code that's generated to return the newly created Id to Power Automate Desktop.

In case you've never heard of SAP's PM Notification or you don't have access to it, don't worry you'll still be able understand the steps needed to extract such data for your own scenario.

Here are the steps:

  1. Confirm that all SAP GUI scripting configurations are done.

  2. Open SAP Logon and select the SAP system to which you want to sign in.

    Extract data from SAP GUI UI by using Power Automate - Power Automate (2)

  3. Select Customize Local Layout (Alt+F12), and then select Script Recording and Playback....

    Extract data from SAP GUI UI by using Power Automate - Power Automate (3)

  4. Select More.

  5. Under Save To, provide the file path and filename where you want to store the captured user interactions.

    Extract data from SAP GUI UI by using Power Automate - Power Automate (4)

  6. Select the Record Script button to start the screen capturing process. Every interaction you do now in SAP is captured as repeatable VBScript commands.

    Note

    If you recorded steps and saved to this file before, you'll need to confirm if you want to overwrite the file.

  7. Enter transaction code IW21, and then select Enter.

  8. Provide the Notification type, and then select Enter.

  9. Enter a Short Text, Planner Group, Main WorkCtr, and any other field that you need.

    Extract data from SAP GUI UI by using Power Automate - Power Automate (5)

  10. Select Save (Ctrl+S) on the toolbar.

  11. Back in the Create PM Notification initial form, you'll notice a new status message in the status bar in the lower-left corner of the UI.

    Extract data from SAP GUI UI by using Power Automate - Power Automate (6)

  12. Select Exit (Shift+F3) on the toolbar, and then stop the recording.

  13. Optionally, log off from SAP and close all SAP windows.

Let's examine the generated VBScript code:

Extract data from SAP GUI UI by using Power Automate - Power Automate (7)

Screenshot of VBScript generated during SAP Notification creation IfNotIsObject application Then SetSapGuiAuto GetObject quot SAPGUI quot Setapplication SapGuiAuto GetScriptingEngine EndIf IfNotIsObject connection Then Setconnection application Children 0 EndIf IfNotIsObject session Then Setsession connection Children 0 EndIf IfIsObject WScript Then WScript ConnectObjectsession quot on quot WScript ConnectObjectapplication quot on quot EndIf session findById quot wnd 0 quot maximize session findById quot wnd 0 tbar 0 okcd quot text quot IW21 quot session findById quot wnd 0 quot sendVKey0 session findById quot wnd 0 usr ctxtRIWO00 QMART quot text quot M2 quot session findById quot wnd 0 usr ctxtRIWO00 QMART quot caretPosition 2 session findById quot wnd 0 quot sendVKey0 session findById quot wnd 0 usr subSCREE shortenedcommand quot text quot MyNotificationShortText quot session findById quot wnd 0 usr tabsTAB_ shortenedcommand quot text quot 010 quot session findById quot wnd 0 usr tabsTAB_ shortenedcommand quot text quot 0001 quot session findById quot wnd 0 usr tabsTAB_ shortenedcommand quot text quot MAIN quot session findById quot wnd 0 usr tabsTAB_ shortenedcommand quot setFocus session findById quot wnd 0 usr tabsTAB_ shortenedcommand quot caretPosition 4 session findById quot wnd 0 tbar 0 btn 11 quot press session findById quot wnd 0 tbar 0 btn 15 quot press.

Now, let's adjust the generated code to include a step that extracts, trims, and then returns the new notification ID to the Run VBScript action.

Extract data from SAP GUI UI by using Power Automate - Power Automate (8)

Screenshot of adjusted VBScript that returns SAP Notification to Power Automate Desktop via a variable 39 ThisistheSavebutton session findById quot wnd 0 tbar 0 btn 11 quot press 39 ThisisthefullStatusBartextthatcontainthedatatobeextracted statusBarMessage session findById quot wnd 0 sbar pane 0 quot text 39 TrimmingandremovinganytextsurroundingournewnotificationId notificationID Trim Replace Replace statusBarMessage quot Notification quot quot quot quot saved quot quot quot 39 ThisistheExitbutton session findById quot wnd 0 tbar 0 btn 15 quot press 39 ThiswritesthenewlycreatedIdtotheRunVBScriptoutputvariableinPowerAutomateDesktop WScript EchonotificationID.

This sets the VBScriptOutput variable of the Run VBScript action to the newly created notification ID.

Extract data from SAP GUI UI by using Power Automate - Power Automate (9)

If you want to see the contents of the VBScriptOutput, you can use a display message action, similar to the output in the following images.

Extract data from SAP GUI UI by using Power Automate - Power Automate (10)

Extract data from SAP GUI UI by using Power Automate - Power Automate (11)

Low-code approach

The low-code approach uses actions and custom selectors to extract newly generated record IDs or other status messages that are important for downstream flow processing.

The following steps won't go into detail about how to record or use manual action design to create a new SAP PM Notification record. Please review Low-code or No-codeRPAwithSAPGUIinPowerAutomateDesktop if you need a refresher on how to do that.

Follow these steps for a low-code approach:

  1. Use the desktop recorder or manual action design to capture all controls that you need for the SAP PM Notification process.

  2. Create a notification record, and capture the status text that appears after you select Save on the toolbar of the Create PM Notification screen.

    Extract data from SAP GUI UI by using Power Automate - Power Automate (12)

    After the item is saved, you'll be redirected to the previous screen where you should see a new notification number in the status bar text.

  3. Now, go back to Power Automate Desktop, search for an action named Get details of a UI element in window, and add it to your authoring canvas.

  4. Select the UI element dropdown menu, and then select Add a new UI element button.

    Extract data from SAP GUI UI by using Power Automate - Power Automate (13)

  5. Select the SAP Easy Access window and hover over the status bar until a red border labeled Gui Statusbar appears. While the border is active, hold down Ctrl and then click to select the status bar.

    Extract data from SAP GUI UI by using Power Automate - Power Automate (14)

  6. Select Save.

    Extract data from SAP GUI UI by using Power Automate - Power Automate (15)

  7. Search for the Replace text action in the Actions pane, and drag it onto the design canvas.

  8. In Text to find, enter Notification. Under Replace with, enter a blank string by entering the following characters: %''%

    Extract data from SAP GUI UI by using Power Automate - Power Automate (16)

  9. Add another Replace text action, and rename the Variables produced to %NotificationId%. In Text to find, enter save, and under Replace with, enter a blank string (%''%).

    Extract data from SAP GUI UI by using Power Automate - Power Automate (17)

  10. Search for the Trim text action on the Actions pane, drag it onto the design canvas, select %NotificationId% as Text to trim value and rename Variables produced to %TrimmedNotificationID%.

    Extract data from SAP GUI UI by using Power Automate - Power Automate (18)

  11. Search for the Display message action on the Actions pane, and drag it onto the design canvas. Set Message box title and Message to display to suit your needs.

    Extract data from SAP GUI UI by using Power Automate - Power Automate (19)

  12. Run the automation that creates a new SAP PM Notification and extracts its newly generated notification ID that can be displayed as shown in the following image.

    Extract data from SAP GUI UI by using Power Automate - Power Automate (20)

Next step: Summary of the benefits of VBScript vs. actions for SAP GUI automation

Extract data from SAP GUI UI by using Power Automate - Power Automate (2024)
Top Articles
Latest Posts
Article information

Author: Mrs. Angelic Larkin

Last Updated:

Views: 6288

Rating: 4.7 / 5 (67 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Mrs. Angelic Larkin

Birthday: 1992-06-28

Address: Apt. 413 8275 Mueller Overpass, South Magnolia, IA 99527-6023

Phone: +6824704719725

Job: District Real-Estate Facilitator

Hobby: Letterboxing, Vacation, Poi, Homebrewing, Mountain biking, Slacklining, Cabaret

Introduction: My name is Mrs. Angelic Larkin, I am a cute, charming, funny, determined, inexpensive, joyous, cheerful person who loves writing and wants to share my knowledge and understanding with you.