Purpose With CallJS you can call a JavaScript function from a GuiXT Script or InputScript.

Component "GuiXT Controls" is needed for this command.
 

Example CallJS msg = test1

The JavaScript function "test1" is called. The function result is stored in string format into variable V[msg].
 

Format 1 CallJS  funcname "par1" "par2 "par2" ...

The  JavaScript function "funcname" is called. The specified strings "par1", "par2",... are passed to the function. You can use the notation  "&V[varname]" as parameter if you want to pass the value of a GuiXT variable.
 

Format 2 CallJS  varname = funcname "par1" "par2 "par2"

The  JavaScript function "funcname" is called. The specified strings "par1", "par2",... are passed to the function. The function result is stored in string format into the variable V[varname].
 

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

When the first CallJS commmand 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 Web 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   SAPWR:ZGUIXT.jslib01.js
JSLibrary   SAPWR:ZGUIXT.jslib02.js
JSLibrary   SAPWR:ZGUIXT.jslib03.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.
 

Object references JavaScript is an object based programming language that allows you to create objects dynamicall. EIther ActiveX components that you create with guixt.CreateObject() or via the GuiXT "Control" command, or JavaScript objects.

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.

JavaScript, being an untyped programming language, has its limitations when programs are above a certain level of complexity. In this case you can implement an ActiveX component in a better suited typed language such as Visual Basic .NET or C#  and make use of this component in your JavaScript code.
 

Debugging You can invoke the debugger with a  "debugger" command in a JavaScript function and use "MS VIsual Sudio" for debugging.
Example 2 We start Excel and pass some demo values:

// GuiXT Script

// set some demo values
Set V[region.1] "Americas"
Set V[sales.1] "2584"
 
Set V[region.2] "Europe"
Set V[sales.2] "1228"

Set V[region.3] "Asia"
Set V[sales.3] "1628"

// call excel
CallJS start_excel 3

 

// JavaScript
functionstart_excel(rows)
{
    var XL = guixt.CreateObject("Excel.Application");
      
    XL.Visible = true;
   
    XL.Workbooks.Add();
            
    XL.Columns(1).ColumnWidth = 30;
    XL.Columns(2).ColumnWidth = 20;
        
    for (var k=1; k<=rows; k++)

    {  

        XL.Cells(k,1).Value = guixt.get("region." + k);
        XL.Cells(k,2).Value = guixt.get("sales."  + k);
    };

  XL = null;

}

Components GuiXT + Controls