-
Notifications
You must be signed in to change notification settings - Fork 0
/
sapGuiScripting.js
105 lines (85 loc) · 3.11 KB
/
sapGuiScripting.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
var jacob = JavaImporter(
com.jacob.activeX.ActiveXComponent,
com.jacob.com.ComThread,
com.jacob.com.Dispatch,
com.jacob.com.Variant
);
function main() {
with (jacob) {
// Invokes SAP GUI Scripting method
call = (session, id, name, parameter) => {
if (typeof parameter === "undefined" || parameter === null) {
return ActiveXComponent(session.invoke("findById", id).toDispatch())
.invoke(name);
} else {
return ActiveXComponent(session.invoke("findById", id).toDispatch())
.invoke(name, parameter);
}
}
// Sets SAP GUI Scripting attribute
set = (session, id, name, parameter) => {
if (typeof parameter === "undefined" || parameter === null) {
ActiveXComponent(session.invoke("findById", id).toDispatch())
.setProperty(name);
} else {
ActiveXComponent(session.invoke("findById", id).toDispatch())
.setProperty(name, parameter);
}
}
// Gets SAP GUI Scripting attribute
get = (session, id, name) => {
return ActiveXComponent(session.invoke("findById", id).toDispatch())
.getProperty(name);
}
ComThread.InitSTA();
var SAPROTWr = new ActiveXComponent("SapROTWr.SapROTWrapper");
var ROTEntry = SAPROTWr.invoke("GetROTEntry", "SAPGUI").toDispatch();
try {
var ScriptEngine = Dispatch.call(ROTEntry, "GetScriptingEngine");
var application = new ActiveXComponent(ScriptEngine.toDispatch());
application.setProperty("HistoryEnabled", false);
var connection = new ActiveXComponent(
application.invoke("Children", 0).toDispatch()
);
var DisabledByServer = connection.getProperty("DisabledByServer")
.changeType(Variant.VariantBoolean).getBoolean();
if(DisabledByServer == true) {
print("Scripting is disabled by server");
ComThread.Release();
return;
}
var session = new ActiveXComponent(
connection.invoke("Children", 0).toDispatch()
);
var Busy = session.getProperty("Busy")
.changeType(Variant.VariantBoolean).getBoolean();
if(Busy == true) {
print("Session is busy");
ComThread.Release();
return;
}
var IsLowSpeedConnection = session.getPropertyAsComponent("Info")
.getProperty("IsLowSpeedConnection")
.changeType(Variant.VariantBoolean).getBoolean();
if(IsLowSpeedConnection == true) {
print("Connection is low speed");
ComThread.Release();
return;
}
set(session, "wnd[0]/tbar[0]/okcd", "text", "/nSE16");
call(session, "wnd[0]", "sendVKey", 0);
set(session, "wnd[0]/usr/ctxtDATABROWSE-TABLENAME", "text", "TADIR");
set(session, "wnd[0]/usr/ctxtDATABROWSE-TABLENAME", "caretPosition", 5);
call(session, "wnd[0]", "sendVKey", 0);
call(session, "wnd[0]", "sendVKey", 31);
call(session, "wnd[0]", "sendVKey", 0);
call(session, "wnd[0]", "sendVKey", 3);
call(session, "wnd[0]/tbar[0]/btn[3]", "press");
} catch (exception) {
print(exception);
} finally {
ComThread.Release();
}
}
}
main();