cancel
Showing results for 
Search instead for 
Did you mean: 

SAP GUI Script with JavaScript

former_member823631
Discoverer
0 Kudos
2,914

How can I connect SAP GUI with JavaScript?

I can do it in python and java, but my company wants it in JavaScript. Is it even possible? I've been trying for 5 days but I'm not getting anywhere...

Here is the code, what I want to run in JavaScript:

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/ssubAREA01:SAPLZISU_CIC_EECIC_SD_600:0110/ctxtEFINDD_CIC-C_BUPART").text = "4200000032"
session.findById("wnd[0]/usr/ssubAREA01:SAPLZISU_CIC_EECIC_SD_600:0110/ctxtEFINDD_CIC-C_BUPART").setFocus
session.findById("wnd[0]/usr/ssubAREA01:SAPLZISU_CIC_EECIC_SD_600:0110/ctxtEFINDD_CIC-C_BUPART").caretPosition = 10
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/usr/ssubAREA01:SAPLZISU_CIC_EECIC_SD_600:0110/btn742C").press

Accepted Solutions (0)

Answers (1)

Answers (1)

FrankKrauseGUI
Product and Topic Expert
Product and Topic Expert

Hi,

SAP GUI for Windows can replay vbs scripts and js scripts.
If you drop a script like this into a SAP GUI window, it will run SE38 for example:

var GuiAuto = GetObject("SAPGUI");
var application = GuiAuto.GetScriptingEngine;
var connection = application.Children(0);
var session = connection.Children(0);
var window = session.findById("wnd[0]");
window.findById("tbar[0]/okcd").text = "/nse38";
window.sendVKey(0);

If you want to record scripts, you can use SAP GUI for Java to record with Javascript and replay with slight changes in SAP GUI for Windows.

Best regards,
Frank

AndrewBarnard
Contributor

frank.krause wrote "If you want to record scripts, you can use SAP GUI for Java to record with JavaScript and replay with slight changes in SAP GUI for Windows"

It would be nice if the SAP GUI for Windows record gave an option to record JavaScript 🙂

terry-lzx
Discoverer
0 Kudos

Frank

I am using google sheets App script to run below code, but error happened in "GuiAuto = GetObject("SAPGUI")"

function myFunction() { var GuiAuto = GetObject("SAPGUI"); var application = GuiAuto.GetScriptingEngine; var connection = application.Children(0); var session = connection.Children(0); var window1 = session.findById("wnd[0]"); window1.findById("tbar[0]/okcd").text = "ZBPP053"; window1.sendVKey(0); window1.findById("usr/ctxtP_WERKS").text = "ZBPP053"; window1.findById("usr/ctxtS_DISPO-LOW").text = "312"; window1.findById("usr/ctxtS_DISPO-LOW") = setFocus; window1.findById("usr/ctxtS_DISPO-LOW").caretPosition = 3; window1.findById("tbar[1]/btn[8]").press; window1.findById("tbar[1]/btn[45]").press; var window2 = session.findById("wnd[1]"); window2.findById("usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[4,0]").select; window2.findById("usr/subSUBSCREEN_STEPLOOP:SAPLSPO5:0150/sub:SAPLSPO5:0150/radSPOPLI-SELFLAG[4,0]").setFocus; window2.findById("tbar[0]/btn[0]").press;}