cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Check for popup within script

0 Likes
25,695

Hi folks,

I am quite new to VBscripting and trying to create a script that automatically mass generates users via SU01.

Everything worked fine so far but now I am stuck because of a stupid popup.

If a user was created and afterwards deleted and I am going to recreate it, SAP will ask me if I want to use his old office data.

If it does my script gets stuck of course because it wants to continue to supply the user details.

Please have a look at the code (problem is

bold

😞

Dim strFilename, Dialog, fso, conentTextfile

Dim Test

Set Dialog = CreateObject("MSComDlg.CommonDialog")

Set fsobj = CreateObject("Scripting.FileSystemObject")

'Explorer-Dialog zum Öffnen von Dateien

'Titelzeile

Dialog.DialogTitle = "Datei öffnen"

'Suchmaske (hier benutzerdefiniertes Dateikürzel)

Dialog.Filter = "Textdateien-Datei (.txt)|.txt"

'Filterindex

Dialog.FilterIndex = 1

Dialog.MaxFileSize = 260

'Flags setzen: Explorer-Dialog mit langen Dateinamen

Dialog.Flags = &H1814

'Datei öffnen

Dialog.ShowOpen

'Ergebnis der Dateianwahl ausgeben

strFilename = Dialog.Filename

If strFilename <> "" Then
Set textfile = fsobj.OpenTextFile(strFilename,"1")
do while not textfile.AtEndOfStream
'Zeilen einzeln einlesen
TextLine = textfile.ReadLine
UserData = Split(TextLine,",")

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]/usr/ctxtUSR02-BNAME").text = UserData(0)
session.findById("wnd[0]/usr/ctxtUSR02-BNAME").caretPosition = 7
session.findById("wnd[0]/tbar[1]/btn[8]").press

'Here is the problem!!!

Test = session.findById("wnd[1]").Type
if test = "GuiModalWindow" then
session.findById("wnd[1]/usr/btnBUTTON_1").press
end if
'If I check for the popup window (as shown above) and the user didn't exist before (so there is no popup window) the program will exit with an exception because wnd[1] doesn't exist. Is there any possibility to check wether wnd[1] exists?

session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSZA5:0900/txtADDR3_DATA-NAME_LAST").text = UserData(1)

session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSZA5:0900/txtADDR3_DATA-NAME_FIRST").text = UserData(2)

session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSZA5:0900/txtADDR3_DATA-NAME_FIRST").setFocus

session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpADDR/ssubMAINAREA:SAPLSZA5:0900/txtADDR3_DATA-NAME_FIRST").caretPosition = 10

session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO").select

session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUU5:0101/pwdG_PASSWORD1").text = UserData(4)

session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUU5:0101/pwdG_PASSWORD2").text = UserData(5)

session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUU5:0101/ctxtUSLOGOND-CLASS").text = UserData(3)

session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUU5:0101/ctxtUSLOGOND-GLTGV").text = UserData(6)

session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUU5:0101/ctxtUSLOGOND-GLTGB").text = UserData(7)

session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUU5:0101/ctxtUSLOGOND-GLTGB").setFocus

session.findById("wnd[0]/usr/tabsTABSTRIP1/tabpLOGO/ssubMAINAREA:SAPLSUU5:0101/ctxtUSLOGOND-GLTGB").caretPosition = 10

session.findById("wnd[0]/tbar[0]/btn[11]").press

loop

End If

Set Dialog = Nothing

Set fso = Nothing

Thanks in advance and kind regards,

Bastian

View Entire Topic
Former Member

Hi Bastian,

I also came across similar scenario need to handle unexpected popup. I have found a simple solution as below.

If Session.ActiveWindow.Name = "wnd[1]" Then

If Session.findbyid("wnd[1]").Text Like "Delete*" Then Session.findbyid("wnd[1]/usr/btnSPOP-OPTION1").press

End If

Hope it helps.

former_member863284
Discoverer
0 Likes

Hi HanKeat,

Thank you!  I have been looking for a simple way to do this for years and I stumbled across this.  It works perfectly!

Former Member
0 Likes

Thanks HanKeat

It helped me lot