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

Error Message : Object required 'WScript'-

Former Member
0 Likes
3,690

Hello,

I cannot make WScript.sleep to work..

When I start to run the script, here is what I get : Object required: 'WScript' -

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 = "QF01"
session.findById("wnd[0]").sendVKey 0

WScript.Sleep 500

session.findById("wnd[0]/usr/ctxtQALS-PRUEFLOS").text = "30000020135"
session.findById("wnd[0]/usr/ctxtQALS-PRUEFLOS").caretPosition = 11
session.findById("wnd[0]").sendVKey 0
Wscript.Sleep 300000
session.findById("wnd[0]/usr/ssubSUB_ITEM_OVERVIEW:SAPLQFFE:4100/tblSAPLQFFEITEM_OVERVIEW_SER/ctxtQFAAI-FEGRP[1,2]").setFocus
If session.findById("wnd[0]/usr/ssubSUB_ITEM_OVERVIEW:SAPLQFFE:4100/tblSAPLQFFEITEM_OVERVIEW_SER/ctxtQFAAI-FEGRP[1,2]").caretPosition = 0 Then
session.findById("wnd[0]/usr/ssubSUB_ITEM_OVERVIEW:SAPLQFFE:4100/tblSAPLQFFEITEM_OVERVIEW_SER/ctxtQFAAI-FEGRP[1,3]").setFocus
Wscript.Sleep 300000
session.findById("wnd[0]/usr/ssubSUB_ITEM_OVERVIEW:SAPLQFFE:4100/tblSAPLQFFEITEM_OVERVIEW_SER/ctxtQFAAI-FEGRP[1,3]").text = "qfdc"
End If

Accepted Solutions (0)

Answers (2)

Answers (2)

FrankKrauseGUI
Product and Topic Expert
Product and Topic Expert
0 Likes

Hello Inas,

such commands can only work if the script is started via the scripting host wscript.exe / cscript.exe.

The standard script header created by SAP GUI contains this:
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject application, "on"
End If

You can easily do similar checks in your script.

However, if you want a sleep to work via wscript, then you need to run the script as mentioned above.
For example:
- Open command prompt (must be running with the same permissions as SAP GUI!)
- wscript.exe <scriptfile>

And regarding the sleep(300000). Do you really want to wait that long?

Best regards,
Frank

mbov
Explorer
0 Likes

Why are you using WScript.Sleep? Usually, the script will wait on it's own until an input is made. Just scrap WScript completely.

If you need to sleep a certain time (seems like you want to wait 5 minutes here), use the specific language equivalent. E.g. Thread.Sleep in C#