User Modification SAP GUI Script

Simple SAP GUI Script for modifying users’ email massively.
It takes data from a text file where each line has an user and email separated by ‘;’
All the work is done in SU01 transaction.

Check the code:

If Not IsObject(application) Then
   Set SapGuiAuto  = GetObject("SAPGUI")
   Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
   Set connection = application.Children(0)
End If
If Not IsObject(session) Then
   Set session    = connection.Children(0)
End If
If IsObject(WScript) Then
   WScript.ConnectObject session,     "on"
   WScript.ConnectObject application, "on"
End If

session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "/nSU01"
session.findById("wnd[0]").sendVKey 0

Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1
Set objFile = objFSO.OpenTextFile ("users.csv", ForReading)

Do Until objFile.AtEndOfStream
        On Error Resume Next
        strNextLine = objFile.Readline
        If strNextLine <> "" Then
                sep = InStrRev( strNextLine , ";")
                If sep > 0 Then
                        usuario = Mid(strNextLine, sep + 1)
                        email = Left(strNextLine, sep - 1)
                        'WScript.StdOut.Write( usuario & " - " & email & VbCrLf)
                        session.findById("wnd[0]/usr/ctxtSUID_ST_BNAME-BNAME").text = usuario
                        session.findById("wnd[0]/usr/ctxtSUID_ST_BNAME-BNAME").caretPosition = 8
                        session.findById("wnd[0]/tbar[1]/btn[18]").press
                        session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSUID_MAINTENANCE:1900/txtSUID_ST_NODE_COMM_DATA-SMTP_ADDR").text = email
                        session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSUID_MAINTENANCE:1900/txtSUID_ST_NODE_COMM_DATA-SMTP_ADDR").caretPosition = 16
                        session.findById("wnd[0]/tbar[0]/btn[11]").press
                End If
        End If
Loop
objFile.Close
 

 

If Not IsObject(application) Then
   Set SapGuiAuto  = GetObject("SAPGUI")
   Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
   Set connection = application.Children(0)
End If
If Not IsObject(session) Then
   Set session    = connection.Children(0)
End If
If IsObject(WScript) Then
   WScript.ConnectObject session,     "on"
   WScript.ConnectObject application, "on"
End If

session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "/nSU01"
session.findById("wnd[0]").sendVKey 0

Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1
Set objFile = objFSO.OpenTextFile ("users.csv", ForReading)

Do Until objFile.AtEndOfStream
        On Error Resume Next
        strNextLine = objFile.Readline
        If strNextLine <> "" Then
                sep = InStrRev( strNextLine , ";")
                If sep > 0 Then
                        user = Mid(strNextLine, sep + 1)
                        email = Left(strNextLine, sep - 1)
                        session.findById("wnd[0]/usr/ctxtSUID_ST_BNAME-BNAME").text = user
                        session.findById("wnd[0]/usr/ctxtSUID_ST_BNAME-BNAME").caretPosition = 8
                        session.findById("wnd[0]/tbar[1]/btn[18]").press
                        session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSUID_MAINTENANCE:1900/txtSUID_ST_NODE_COMM_DATA-SMTP_ADDR").text = email
                        session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSUID_MAINTENANCE:1900/txtSUID_ST_NODE_COMM_DATA-SMTP_ADDR").caretPosition = 16
                        session.findById("wnd[0]/tbar[0]/btn[11]").press
                End If
        End If
Loop
objFile.Close
 

Leave a Reply

Your email address will not be published. Required fields are marked *