We start with the JavaScript function call in GuiXT scripts, a feature that is
useful in its own right and in its application to ActiveX controls.
This is how to proceed:
Create a
file with the extension .js, e.g. "lib.js".
In this file
you write a JavaScript function, for example:
function test()
{
return "Hello World";
}
If
you want to realize a larger project with GuiXT controls, it is
recommended to use a special editor for JavaScript. We recommend
Microsoft Visual Studio, which is also available in a free "Express
Edition".
You enter the
name of the file in the GuiXT profile:
You can later specify several files here, separated by semicolons, in
case a single file becomes too large. All files are loaded and can
access common global variables.
Attention: If you change something in your JavaScript file
after a test, you have to open a new SAP GUI mode with "/O..." for the
next test, because in the old mode the old version of your JavaScript
file is still running. The entire JavaScript program is loaded only once
within a mode, so that e.g. global variables keep their value.
In a GuiXT
script or InputScript you call the JavaScript function with the keyword
"CallJS". You can output the value as a "message" for testing purposes:
CallJS msg = test
Message
"S: &V[msg]"
-statusline
This means:
The JavaScript function "test" is called and the result is placed in the
GuiXT variable V[msg]. If you are not interested in the return value,
you can simply call a VBScript function with
CallVBS test
The result is a SAP GUI message with the text from the JavaScript
function: