Description

When referencing properties, syntax is often an issue, particularly when creating JavaScript code. Often there are syntax alternatives that get the same result while avoiding some unpleasant syntax side effects. This article provides examples.

Solution

If you use the property reference, the value of the property appears in the step's Full Details. Only the result of the of the JavaScript is shown, which means the JavaScript is more difficult to debug if there are problems.

Examples

As of ElectricCommander v3.0, JavaScript is read-only, and only API object reference access is supported.

Property syntax

Below are examples showing a property reference in a Perl print statement. The properties are replaced during property expansion. First, a property expansion reference, second, the JavaScript form of a property reference, third, a property expansion reference in a JavaScript condition, fourth, a Javascript form of a property reference in a JavaScript condition.

The above JavaScript syntax creates a regular expression using the evaluated step name contents as expected.

JavaScript and dashes and properties

In JavaScript, the dash character can mean minus or it may be in a name. The following incorrect example shows how to reference a property name savedResourceName with a minus sign as the value of the property, say foo-bar.

Using JavaScript to reference objects by Id

The Javascript 'objects' array is indexed by entity references (e.g. "project-1", "job-2", "workflow-3"). It returns the corresponding object, which you can then use to fetch intrinsic or custom properties by name (e.g. projectName). To reference the name of the object after you have the Id, use the following syntax: