| Purpose | With CallJS you can call a JavaScript function from a GuiXT Script or InputScript. |
|
Examples Further examples and explanations |
CallJS
msg = test1 CallJS msg = mytestlib.test1 The JavaScript function "test1" is called. The function result is stored in string format into the GuiXT variable V[msg]. |
| Format | There are two different notations, depending on whether you want to run JavaScript in older IE mode or Chromium mode:
// IE mode
CallJS libname.funcname "par1" "par2" "par2" ... CallJS varname = libname.funcname "par1" "par2" "par3" ...
Both notations call the JavaScript function “funcname”. The specified strings ‘par1’, “par2”,... are passed to the function as parameters and the return value of the function is placed in the GuiXT result variable.
Future-proof: The web browser control used in GuiXT's IE mode is also used in the Edge browser as the basis for “Internet Explorer Mode,” which is guaranteed by Microsoft until 2029. However, a switch to Chromium may be necessary from 2030 onwards. |
| Security | JavaScript in combination with ActiveX objects is able to perform critical operations such as destroying files or changing registry values, comparable to Visual Basic, Java or C++ . As a consequence, the same security rules that apply for programs written in these languages have to be applied to JavaScript functions that you rollout to other users. |
| Details for the IE mode |
When the first
CallJS
command is performed in a SAP GUI mode, all JavaScript library files
specified in GuiXT profile are loaded. The functions and global variables
in these .js files need to have a unique name across all files, since a
single namespace is used when loading the files. Please observe that any
commands outside of function or class declarations will be executed when
the files are loaded. Global JavaScript variables retain their values within
each SAP GUI mode.
You may store the JavaScript files in the SAP MIME Repository and maintain them centrally, facilitating quality control and rollout. For example, the following statements in the configuration file "guixt.ini" will load three JavaScript files from SAP Web Repository:
JSLibrary SAPMR:SAP/BC/BSP/SAP/GUIXT/JS/jslib01.js Syntax errors in any one of the JavaScript files should be avoided, since in this case the loading of the functions is terminated with a syntax error message. All parameters are passed to the JavaScript function as string values, and the return value is stored as a string value in the specified script variable. There is only one exception to this rule: object references are handled differently; see next section. It is possible to read and write GuiXT variables within the JavaScript function; for details on how to proceed see Object "guixt" in JavaScript. This allows you to implement a kind of parameter passing by reference: simply pass the name of the GuiXT script variable instead of its value, and use guixt.get() and guixt.set() to access the variable using its name. GuiXT supports parameter passing of object references in both directions. It uses a string representation of the object reference when it is stored into a GuiXT script variable, and converts automatically to or from the object reference (technically: an IDispatch interface). For example, you can define a JavaScript class, create an object of this class in JavaScript, pass the object reference to GuiXT and store it into a GuiXT script variable, then call a second JavaScript function, pass GuiXT variable that contains the object reference and access attributes and methods of the object. |
| Details for the Chromium mode | When a
CallJS statement is executed for the first time per SAP GUI mode, the HTML file libname.html is searched for in the script directories and loaded into the WebView2 environment. The function names and global variables only need to be unique within the HTML file. Global JavaScript variables in the HTML file retain their value within a SAP GUI mode.
Unlike in IE mode, it is not possible to transfer object references. However, you can use the guixthost object in JavaScript to transfer object references between JavaScript and GuiXT. Examples can be found under the link “Further examples and explanations” in the section above. |
|
WebView and CallJS
in Chromium mode |
If you display an HTML file with the statement
WebView ... name="mywebview" you can call JavaScript functions in the displayed HTML file by specifying the WebView variable as libname in angle brackets: CallJS <mywebview>.funcname "par1" "par2" "par2" ... This allows you, for example, to dynamically control the display attributes of the HTML file. Examples can be found under the link “Examples and explanations” in the section above. |
| Tips & Tricks | |
| Components | GuiXT + Controls |