You have been redirected from an outdated version of the article. Below is the content available on this topic. To view the old article click here.

Built-In Functions

Search results for "Built-In Functions"

JavaScript

JavaScript scripting contexts are explicitely defined by enclosing dollar sign and double curly brackets (${{}}) or single curly brackets ({}) within auto-scripting contexts. In an R context, access to Structr’s built-in functionality is provided via the Structr keyword or dollar sign $ as a global variable.

The JavaScript engine provides special bindings allowing built-in functions to be called directly on the binding object. Built-in functions can be called using Structr.call([Function Name], [Parameters]) and Structr constants can be retrieved using Structr.get('[Constant Name]').

This allows expressions like:

Built-in Functions

Built-in functions provide access to the Structr Backend API from within a scripting context. You can run database queries, process the results, create or modify objects, and much more.

Python (Experimental)

A Python scripting context is explicitely defined by ${python{}} (or python{} in an auto-scripting context). In a Python context, access to Structr’s built-in functionality is provided via the Structr keyword as a global variable. Built-in functions can be called using Structr.call([Function Name], [Parameters]) and Structr constants can be retrieved using Structr.get('[Constant Name]').

R (Experimental)

An R scripting context is explicitely defined by ${Renjin{}} (or Renjin{} in an auto-scripting context). In an R context, access to Structr’s built-in functionality is provided via the Structr keyword as a global variable. Built-in functions can be called using Structr.call([Function Name], [Parameters]) and Structr constants can be retrieved using Structr.get('[Constant Name]').

JavaScript

In any other than the JavaScript context, you are required to use get() and call() to access built-in functions and constants. This results in code like the following example.

StructrScript

The above example shows the use of three different built-in functions. The find() function executes a database query and returns the result collection. extract() converts the collection of database objects into a collection of strings and join() concatenates the collection of strings into a single string, using the given separator between the elements.

Template Expressions

In addition to the built-in functions provided by the scripting environment, Structr introduces a set of predefined keywords in the template elements that allow access to data in the current context, for example the logged on user, the current page, or any existing request parameters.

Import from Webservices

The following example shows how to use built-in functions in a schema method to consume a webservice and process the results.

StructrScript

StructrScript is the name of the internal scripting language that can be used in Content or Template nodes, Template Expressions, Show Conditions and HTML attributes. It is a simple interpreted functional scripting language that provides access to Structr’s functionality through a set of functions and keywords. StructrScript has no control structures, it is interpreted like a fully functional language, although some of the Built-In Functions have side effects.

Import from Webservices

Structr provides a number of built-in functions to access external data sources and transform the data: GET, PUT, POST, from_csv, from_json, from_xml. You can then use JavaScript to process the results and create objects using the create() function mentioned in the previous section.

Using Scripting to create data

The Structr Scripting Engine provides a number of built-in functions to create, modify and delete nodes and relationships in the database.

Output on the page

If you use template expressions and built-in functions in a content element, and an error occurs, the error message will be written into the HTML output. If there is an error message on the page, or a usage message for a built-in function, the error is very likely in a dynamic content element in that page.

Logging

nodeextender.log Enables the logging of generated Java code of the dynamic schema entities to the logfile. This setting allows you to investigate and debug the generation of Java code for your schema entities in cases where something goes wrong.
nodeextender.log.errors Enables the logging of Java compilation errors when compiling the dynamic schema of your application.
log.requests Enables full request logging for all requests handled by Structr. Caution, the log file can get very large when a lot of requests with lots of content are made.
log.debug Controls the debug() built-in function, which will behave exactly like the log() function if enabled.
log.functions.stacktrace Enables stacktrace logging for script calls and built-in functions. If enabled, a scripting error will write the full Java stack trace to the logfile.
log.prefix Sets the prefix for the request log file that is written when log.requests is enabled.
log.javascript.exception.request Adds path, queryString and parameterMap to JavaScript exceptions (if available) if enabled.
log.directorywatchservice.scanquietly Prevents logging of each scan process for every folder processed by the directory watch service.

Function Query

In the JavaScript context the same built-in functions are available as in the StructrScript context but a lot of convenient JavaScript functionality is available as well.

In the StructrScript context all built-in functions can be used to collect, filter, sort, etc. the data for the repeater.

Paths

base.path Path of the Structr working directory. All files will be located relative to this directory.
tmp.path Path to the temporary directory. Uses java.io.tmpdir by default.
database.path Path of the Neo4j db/ directory.
files.path Path to the Structr file storage folder.
changelog.path Path to the Structr changelog storage folder.
data.exchange.path Path to the exchange directory. This path is relative to the base path of the Structr installation to prevent access to files outside of the installation directory. The exchange directory is used by the I/O built-in functions read, write and append.
snapshot.path Path to the snapshot directory. This path is relative to the base path of the Structr installation to prevent access to files outside of the installation directory. The snapshot directory is used by the snapshot() built-in function that allows you to read / write the schema of your application from / to a JSON file.
data.webapp.path Path to the webapp directory. This path is relative to the base path of the Structr installation to prevent access to files outside of the installation directory. The webapp directory is used by the internal web server to serve resource files needed by the Structr UI.

StructrScript