s = JS.invoke(function_nameʃ, argument1, ..., argumentNʅ);
Only some CSPro types have conversion routines. The following table summarizes conversion routines, with the conversion described in detail at the provided links:
The function returns the JavaScript function's return value as a string, converted using the value's
toString method. If the JavaScript evaluation ends in an uncaught exception, the exception's message is displayed as an error message and the function returns a blank string.
JS.invoke can execute functions that are part of JavaScript built-in objects, such as static methods in
Math.
JS.invoke("Math.max", 2025, 8.1, 25); // 2025
JS.invoke("Math.max", 2025, 8.1, 25, "5000"); // 5000
JS.invoke("Math.max", 2025, 8.1, 25, "five thousand"); // NaN
function sumArray(values) {
let sum = 0;
// use forEach to sum the values of an array
values.forEach(value => {
sum += value;
});
return sum;
}
Array someNumbersArray(4) = 10, 20, 30, 40;
List someNumbersList = 4, 6, 7, 79, 81, 82;
JS.invoke("sumArray", someNumbersArray); // 100
JS.invoke("sumArray", someNumbersList); // 259
function getCSProVersion(diagnosticsCallback) {
return diagnosticsCallback("version");
}
...it is possible to call into JavaScript and then have JavaScript call back into CSPro.