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 on a feature's attributes.
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 primary power of the JavaScriptCaller 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.
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
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.
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.