on 09-10-2011 2:15 PM
Hello,
I am an SAP end user and do not have a programming background, but am teaching myself VBScript to automate some processes. I have learned quite a bit through reading through the posts on the forums, but I can not figure out how to get the scripts that I write to run on the current sap session. They always run on the first session that is opened.
It seems like there must be something that can be written in the script to use the current session vs the 1st session that is opened. I have found a few threads on the forums that make mention of this problem, but have not found a solution that works.
Any help would be greatly appreciated.
Hi Scriptman,
I have learned a lot reading from your previous posts on various subjects. Here is the start of the script just up to the point where it gets the title of the transaction. It always runs on first session created unless I change the children number to reflect the session that I want it to run on.
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
trans = session.findById("wnd[0]/titl").text
I have tried a couple scripts that you have previously posted and the one that comes closest to doing what I want is :
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
msgbox "Please select a session within the next 3 seconds after clicking ok"
wscript.sleep 3000
set session = application.ActiveSession
trans = session.findById("wnd[0]/titl").text
I would like it to just run on the last session that the user was last accessing without them having to click on the session to activate it after the script is running. Do you know of any way to do this or if it is possible?
Thanks again for all the great information that you have already posted.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Scriptman,
I have been running it from windows, by double clicking on the script. I believe it then uses wscript.exe which is windows script host. I would ideally like to keep using this method since the user can float a windows toolbar over their SAP sessions and simply click on the shortcut to run the script. It is a few less steps than dragging and dropping or using the sap script playback option.
If it can be done through this method it would be great, otherwise I am open to other suggestions.
Hi j.macc,
In this case, my suggestion would be as follows:
1. Place a link on the desktop to the script.
2. Find a suitable hotkey and save it in the properties of the link.
3. The scripts should begin with the following lines:
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
set session = application.ActiveSession
' Here follows the rest of the script.
4. Attach the desired SAP session.
5. Press the agreed hotkey.
Within the script you could also evaluate the title and then decide what to do. When we run a script with a hotkey, the focus stays where it was before.
An intelligent variant could also be GuiXT for example. If you have time and inclination then look at the commands "image" and "pushButton". The main difference between the two would be that of one is free and the other is not free.
http://www.synactive.com/docu_e/index_docu_e.html
Regards,
ScriptMan
Hello Scriptman/James,
this code segment worked for me as well
msgbox "Please select a session within the next 3 seconds after clicking ok"
wscript.sleep 3000
set session = application.ActiveSession
Thanks so much for this
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you Scriptman.
I knew there was a simple solution. The creating a shortcut to the script and assigning it a hotkey did just what I need.
Thank you for your other suggestion as well. I will look into that.
J macc
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi j.macc,
Perhaps there is a solution. Before, I would need to know how to start the scripts.
Regards,
ScriptMan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.