JavaScriptCaller
Executes a JavaScript script to manipulate the feature. When a specialized task is required, such as custom statistical analysis of an attribute, but Workbench does not provide a transformer suited to the task, JavaScript can perform specialized and complex operations.
Any exceptions generated while running the script will cause the translation to fail.
Note:
Input Ports
Accepts features to be processed by the JavaScriptCaller.
Output Ports
Outputs features that have been processed by the JavaScriptCaller.
Parameters
If JavaScript Mode is set to V8 Engine, the only portion of JavaScript supported is that in the ECMA-262 specification. No HTTP or DOM support is provided. Usual objects and methods provided by a browser environment, such as document() or XMLHTTPRequest() are unavailable. The code is executed with version 3.24.24 of the V8 JavaScript engine.
The primary power of the classic engine is to allow users who are comfortable with JavaScript notation to perform attribute manipulation using calls such as JSON.parse() and JSON.stringify(). Custom functions for logging, getting, and setting attributes are offered in the form of fme_ functions.
If JavaScript Mode is set to Node.js, the script is executed with version 6.9.0 of Node.js.
The Node.js mode allows users who are comfortable with JavaScript to perform specialized and complex operations on a feature’s attributes, and to perform asynchronous I/O using an event driven architecture.
Access to a feature’s attributes is provided via the FME Objects Node.js API. To view the API documentation, navigate to the FME installation folder and go to this location: fmeobjects\nodejs\apidoc\index.html.
FME can access Node.js modules that are stored on the file system. Use the require function to load these modules. FME will search both the standard Node.js module location and the workspace location to find the module to be loaded.
The JavaScript code to be executed.
Exposes any attributes that are created by the JavaScript code being executed so they can be used by other transformers.
V8 Engine FME JavaScript Functions
print Function
The print function has been implemented to print out a custom log message to the standard FME log file.
print("Hello World!");
print(fme_get_attribute("color"));
fme_get_attribute Function
The fme_get_attribute function has been implemented to retrieve an attribute value as an encoded UTF-8 string from the current feature, given a single parameter containing the attribute name string.
print(fme_get_attribute("color"));
>"0,0,1"
fme_set_attribute Function
The fme_set_attribute function has been implemented to set an attribute name and value as an encoded UTF-8 string attribute on the current feature, given two parameters containing the attribute name and value strings.
fme_set_attribute("color", "red");
fme_attribute_exists Function
The fme_attribute_exists function checks whether the specified attribute exists on the current feature, and returns true or false depending on whether it does.
print(fme_attribute_exists("foo"));
>false
Editing Transformer Parameters
Using a set of menu options, transformer parameters can be assigned by referencing other elements in the workspace. More advanced functions, such as an advanced editor and an arithmetic editor, are also available in some transformers. To access a menu of these options, click beside the applicable parameter. For more information, see Transformer Parameter Menu Options.
Transformer Categories
FME Licensing Level
FME Professional edition and above
Search FME Knowledge Center
Search for samples and information about this transformer on the FME Knowledge Center.