on 11-02-2007 11:43 AM
Hi everyone. This is my first post here, and I'll admit I'm rather inexperienced with scripting, so any help you can provide is appreciated!
We are using a new document imaging program that retrieves values from SAP using scripting. There seems to be a issue when people open multiple SAP sessions, it keeps wanting to retrieve the values from the first session opened.
We would like to have it so what ever SAP session that was last used before running the script, is the values that are used.
Below is a example of one of our scripts. The field3, tab and folder values are values in my imaging system. This script works, but again it will only take the values of the first SAP session opened. We want one that can take it any active session, not just the first.
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
Set connection = application.Children(0)
Set session = connection.Children(0)
field3=session.findById("wnd[0]/usr/ctxtBKPF-BUDAT").text
tab=session.findById("wnd[0]/usr/txtBKPF-XBLNR").text
folder=session.findById("wnd[0]/usr/ctxtRF05A-NEWKO").text
Thanks in advance for any suggestions!
Hello Jason,
see the "Programming API", which is available under "SAP GUI scripting" at http://service.sap.com/sapgui .
The GuiApplication object has a property ActiveSession, which points to the Session that the user is currently working with, which will be the topmost window.
Best regards
Rolf-Martin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rolf,
Unfortunately I don't have a user name and password for the SAP site... Our parent company has all of that information, I asked them today for the ID but have not heard back.
I did a google search and was able to find some info on a web site reading
"session.activeWindow()" but it didn't seem to help.
From what I found from that site I tried the below, but it still didn't seem to work.
Set aw = session.activeWindow()
field3= aw.findById("wnd[0]/usr/ctxtBKPF-BUDAT").text
Rolf,
I've adjusted my code (see below full code), but it still seems to want to take data only from the first session. If the script is run outside of SAP, would the activewindow thing still detect the last active SAP window?
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
set aw = session.activeWindow()
field3 = aw.findById("usr/ctxtBKPF-BUDAT").text
Hi again,
the problem is caused by
Set connection = application.Children(0)
and
Set session = connection.Children(0)
That way you will always get the first session of the first connection, but not the front most window of all open sessions.
Could you try to make use of ActiveSession of the application object instead, like suggested before?
This also has been discussed in .
Best regards
Rolf-Martin
Rolf,
Again I'm very inexperienced with scripting... I adjusted the code to what is shown below... And I now receive the following error... "Script error detected at line 3. Description: Object doesn't support this property or method: 'application.ActiveSession"
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
Set session = application.ActiveSession
field3 = session.findById("usr/ctxtBKPF-BUDAT").text
Hello,
for making application.ActiveSession return an object, a session needs to be in foreground.
E.g. the "attaching script" message window should be turned off.
Then
Set session = application.ActiveSession
field3 = session.findById("wnd[0]/usr/ctxtBKPF-BUDAT").text
should work.
Best regards
Rolf-Martin
Hello,
I am actually trying to accomplish the same thing.
I am using this code.
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
Set session = application.ActiveSession
field3 = session.findById("/wnd[0]/usr/ctxtBKPF-BUDAT").text
and receive the error: Object Required - session.
Thoughts?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.