Skip to main content
Skip table of contents

Using JavaScript

Scripting in NexJ Studio may be done in Scheme or JavaScript. You can change the language to JavaScript for several locations throughout the application. Some items may only be scripted in Scheme. When you set the language attribute, you can see whether that item supports both or just one of the scripting languages.

If the language is set to Scheme, the editor is context-sensitive. It provides auto-completion hints and visually identifies code elements. If the language is set to JavaScript, the editor is context-neutral. That is, it does not provide auto-completion hints or visually identify code elements.

Not all JavaScript functionality is supported by NexJ. For example, templating is not supported. For more information about using JavaScript in your NexJ application, see NexJ JavaScript differences.

Setting the language property for the project

To set the scripting language for an entire project, open the .metadata file for the project (located in the meta folder for the project) in a text editor. Add the language="js" property to the Metadata tag. For example:

XML
<Metadata coreVersion="13.6.41.0+" name="Project Name" namespace="http://www.example.com/ns/ProjectName" revision="1.3" language="js" version="20.20">

If the language is not specified, the default Scheme language is assumed. You can still set JavaScript as the language for individual class attributes, actions, unit tests, or libraries. In addition, you can still use JavaScript as the language for testing your application in the Minimal Console.

If the JavaScript language is set as the project scripting language, you can still set Scheme as the language for individual class attributes, actions, unit tests, or libraries, as well as use it in the Minimal Console.

Setting the language property for class attributes, class events, and unit tests

You can set the language to JavaScript by adding the language="js" property to the source code or by editing the language property in the Properties view. You can set the language property on class attributes, class events, and unit tests.

To set the language property for a class attribute, open a class in the Class editor. Select an attribute in the Attributes tab and set the language property in the Properties view to js. This allows you to enter JavaScript code in the following fields:

  • Initializer
  • Value
  • Validation

You can also use the language property to set the attribute scripting language to scheme if the project language is set to JavaScript.

If the language property does not exist in the Properties view, or if the only value available is scheme, then the object does not support JavaScript.

If the Properties view is not displayed, open it by selecting Window > Show View > Properties.

You can set the language property for individual attributes, so one class may have both Scheme and JavaScript attributes.

You can also set the language property in:

  • An action in the Actions subtab in the Events tab. This allows you to enter JavaScript code into the Condition and Script fields.
  • A unit test definition, in the Initializer tab, and for each individual test case in the Test Cases tab.

Creating a JavaScript library

When creating a new library, you can specify the library language.

To create a new library, select File > New or press Alt+Shift+N. From the menu, select either Library or JS Library.

You cannot change the library language after it has been created.

You can identify the library language by the icon in NexJ Studio, as well as the suffix for the file name. Scheme library file names end with .scm and JavaScript library file names end with .njs.

Related topics


JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.