the test script:
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 = "mm03"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ctxtRMMG1-MATNR").text = "tax reference"
session.findById("wnd[0]/usr/ctxtRMMG1-MATNR").caretPosition = 13
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[1]/usr/tblSAPLMGMMTC_VIEW").getAbsoluteRow(0).selected = true
session.findById("wnd[1]").sendVKey 0

Tue Apr 09, 2013 8:48 am

SysOpSite Admin

Joined: 26 Nov 2006Posts: 6608

The error you get is likely because you didn't set the job script type correctly. It is likely current set to JavaScript, not VBScript.

In addition that script will not work as is. First of all there is no WScript object in VBScript for applications, secondary, it won't work in non-graphical and in unattended mode especially when the scheduler is running is service. Only in full graphical mode you can use "SendKeys" to simulate keyboard events. And even that is highly unreliable. Imagine that while you are running that king this script some window popup will get in the way and grab system focus, or some other application popup. What could happen after that is anyone's guess.

PS. My two cents opinion... Chaining function calls like "session.findById("wnd[0]").sendVKey" doesn't help at all. It is just as bad as 3 separate function calls, it doesn't cause windows and other applications to stop working while the code is being executed. My suggestion, anything that requires sending keystrokes and mouse events is a non starter for a robust automation solution. Please look for an internal API or some other programmatic method to automate the same.