executeCommand Functions

The following methods allow executing a command on a system object by indicating the alias of the command to use.

 

The executeCommand function allows providing scaled values for the parameters values, while the executeCommandNoScaling takes non-scaled values as value parameters.

 

info

Commands management

Desigo CC scripts can only handle commands that are configured to be executed as software. Consequently, a command can be executed by a script only if its display level is set to Software or GenericDisplayAndSoftware.

 

Command Alias

It is unique per system object which means that a system object cannot have more than one property using the same alias. When executing a command identified by its alias, only the name of the object must be specified, because the target property can be identified searching for the only property that has the given alias. In this way, the command can be identified among the available commands for all the properties of that object. A command can have nameonly, aliasonly, or both.

Syntax

It is possible to command a system object by specifying the command alias. See the following syntax:

 

(one instruction)

var result = executeCommand(<objectReference>, <aliasId>, <commandParameters>, <comment>)

 

var result = executeCommandNoScaling(<objectReference>, <aliasId>, <commandParameters>, <comment>)

 

(two instructions with variable)

var obj = new BrowserObject(<objectReference>);
var result = executeCommand(obj, <aliasId>, <commandParameters>, <comment>)

 

var obj = new BrowserObject(<objectReference>);
var result = executeCommandNoScaling(obj, <aliasId>, <commandParameters>, <comment>)

Parameters Usage

Parameter

Type

Default

Use

Annotation

objectReference

String

BrowserObject

Point

-

Mandatory

CNS full path (reference to the system object location).

aliasId

Integer

-

Mandatory

Alias identifier of the command to execute. Its value can be obtained by checking the text group: Command Macro.

commandParameters

String

Number

BigNumber

Boolean

Date

String Array / Number Array / BigNumber Array / Boolean Array / Date Array

JSON object

-

Optional

Parameters necessary to execute a command.

For the executeCommand function, parameters values must be provided scaled and according to the Scaled unit of the property that is commanded; if the Scaled unit is not set, the value is intended to be in the specified Unit (where applicable).

 

For the executeCommandNoScaling function, the parameters values must be provided non-scaled and according to the Unit of the property that is commanded, regardless of the Scaled unit that may be specified (where applicable).

comment

String

-

Optional

This parameter must be specified in order to execute the command successfully when Validation profile = Enabled.

Note that:

    var parameters = {"Priority": 16, "Value": 1}

Result

Error Handling

Errors can occur in case:

Examples of Use

 

How to access and print to Console the result of a command execution call

function printCommandResult(commandResult) {

    if (commandResult.error)

        console("Command failed. Error = '{0}'. Error id = {1}", commandResult.error.message, commandResult.error.id);

    else

        console("Command succeeded");

}

 

An easier way to print the result of the call is, for example:

console(commandResult)

 

How to start and stop a BACnet driver object

var object = new BrowserObject("System1.ManagementView:ManagementView.ManagementSystem.Servers.Server.Drivers.GmsBacnetDriver_1");

var result = executeCommand(object, 32);

var result = executeCommand(object, 33);

//32 is the Alias ID "Start"

//33 is the Alias ID "Stop"

 

Note that the command is used and defined by alias("Start"=32 and "Stop"=33). The first call will start the BACnet driver, while the second call will stop the driver.

 

How to start a backup operation on the server

var result = executeCommand("System1.ManagementView:ManagementView.ManagementSystem.Servers.Server", 26);

//26 is the Alias ID "Backup" for the command BackupExecute

or

var result = executePropertyCommand("System1.ManagementView:ManagementView.ManagementSystem.Servers.Server", "Backup.Status", "Start");

 

The call results in starting the project backup. Note that the command BackupExecute is used and defined by alias (26). Such command has also “Name” which means that the same result can be obtained by calling the commanding the Backup.Status property of the Main Server or using the Start command.

 

How to command an object with Validation profile = Enabled

The following example shows how to start the backup on the Main Server with Validation profile = Enabled.

var result = executeCommand("System1.ManagementView:ManagementView.ManagementSystem.Servers.Server", 26, null, "my comment");