Introduction to the CrossmarX Scripting API

The CrossmarX Scripting API (API stands for Application Programming Interface) is the collection of all functions that allow a script in your application to interact with the CrossmarX Application Engine. Examples of such interactions are: getting a value from a record; querying the database of your application; sending an email, and so on. In order to successfuly use the CrossmarX Scripting API in your scripts, it is important to consider the basis for all of these functions provided by the API, which mainly consists of two components: objects, and methods, which we will explore in detail below. Please also note that the CrossmarX Scripting API is not a programming language; it is just the aforementioned set of functions available to you as a developer of application scripts, regardless of the programming language you choose to implement those scripts in. That being said, the Scripting API is at this moment mostly aimed at, and optimized for, use with JavaScript. However, ongoing developments include a dedicated version of the Velocity Templating Language to be used with this API, and popular languages of the likes of Python and Ruby are also likely to be made available in the foreseeable future.

 

Objects and methods

Objects are, basically, independent units of data that may be thought of as functionally meaningful. A string value containing the text "This string is an object" is an example of an object, as is a record from the database of your application, or a list of date values. Objects can always be assigned to a variable in your script in order for you to use that object, and may be handed to you by the CrossmarX Application Engine as a parameter to your script, depending of its context and purpose. A script for a calculation, for instance, will always be invoked with the record for which that calculation is to be executed, as a parameter (conveniently named "record").

Every object that you use in your scripts has a specific type, and this type largely determines what you may or may not do with an object. In the three examples of objects above, the respective types of these objects are mentioned in italics: "string", "record", and "list" and "date" (list is an example of a (type of) object that contains other objects, which have a type of their own, "date" in this example).

By and of itself, an object is quite static. It may simply be passed around between your scripts and the Engine, but in order to fully use, or manipulate an object, you have to invoke methods on it. Methods may be thought of as operations that are specific for a certain type of object. Consider an email (which is another exmaple of an object) to be sent from your application: it makes sense to instruct this email object to whom it should be sent, and what its contents are to be. Objects of the "email" type provide specific methods to do so. On the other hand, were you to have an object of type "integer" (a whole number), this object would have no "recipient" or "content", so it does not provide any such methods. Likewise, objects of type "record" provide methods for, e.g., validating and saving changes to that record, as those are operations that are specific for records. Methods may require values to be provided for their parameters ("arguments"), as is the case with the methods for setting the recipient and contents of an email, and these arguments themselves are objects. Other methods do not require any parameters (besides, formally, the object to be acted upon).

Methods are typically (this is ultimately dependent on the programming language used) invoked on objects by appending the name of the variable that contains the object with a dot ("."), the (name of the) method, and a list of arguments in parentheses. To invoke the method "save" on an object of type "record" in variable "myRecord": myRecord.save(). Note that although the method save does not required any arguments, you still need to include the enclosing parentheses. Arguments to a method may be provided in place (a so called "literal") or by means of a variable: myEmail.setTo("info@crossmarx.nl") or myEmail.setTo(recipient), where the variable recipient obviously should contain an email address.

 

Using the CrossmarX Scripting API

As mentioned before, the CrossmarX Scripting API is not in itself a programming language, and is being developed to be available to scripts in any of the supported languages that the developer might choose to use. Currently, whereever a script can be written in your application (with some notable exceptions), the choice for the programming language of that script is between JavaScript and Velocity script. If you select JavaScript as your language of choice, your script will always interact with the CrossmarX Application Engine through the CrossmarX Scripting API. Velocity script, however, is a legacy option that operates on its own API, which defines its own set of objects and methods. A new version of the Velocity language (known as "GraVel") does make use of the CrossmarX Scripting API, but is still being developed. This means that for now your only means to use the CrossmarX Scripting API is by selecting JavaScript as language of your scripts.

Perhaps the most important thing to know when you are developing scripts using the CrossmarX Script API, is which objects and methods are available to you as a developer. The full documentation of the contents of the API can be found here. All object types (i.e. entities) made available by the Engine are listed here, and for every type the methods that are specific to that type are listed, along with its constructors and properties (if applicable, and which will be further explained elsewhere). Also, you will find information on security (script permissions, see also here), and links to examples.

Given the large, and growing number of entities available, the API documentation is grouped by module. A module is little more than a unit of entities that have a common domain, such as data, or gui (for Graphical User Interface). Please see the documentation on modules for more information.