Constants

Each Moobot runs in its own thread and instances of Moobots are independent of each other. The Constants module enables you to share logic, states or flags between Moobots. You can build a key value dictionary mapping that is shared across Moobot instances.

There are many system wide defined Constants that are used in the Events module to define which event to listen for. See the event types table below for more information.

Load the module

The Constants module is available to load into any standard Moobot. To load it, define a new global variable at the top of the Moobot Javascript file. For example:

var constants = MooBot.loadModule('Constants');

Method reference

The Constants module uses the following methods.

put

Associated a specified value with a specified key. Replaces the mapping for an existing key.

Request arguments

The method takes the following arguments.

Name

Type

Description

key

String

The key to associate with the value.

value

Object

The value to associate with the key.

Response

None.

get

Retrieves the value mapped to a specified key.

Request arguments

The method takes the following arguments.

Name

Type

Description

key

String

The key for which to retrieve the value.

Response

The method returns the following parameter:

Type

Description

Object

The value to which the key is mapped, or null if no mapping exists.

getCopy

Available in Moogsoft Enterprise v8.0.0.2. Retrieves the copy of a value mapped to a specified key

Request arguments

The method takes the following argumets:

Name

Type

Description

key

String

The key for which to retrieve the value.

Response

The method returns the following parameter:

Type

Description

Object

The copy of value to which the key is mapped, or null if no mapping exists.

getCopy

Available in Moogsoft Enterprise v8.0.0.2. Retrieves the copy of a value mapped to a specified key. Given a namespace, retrieves the copy of a value mapped to a specified key within the namespace.

Request arguments

The method takes the following arguments:

Name

Type

Description

Namespace

String

Namespace for the constant. For example, Integration type.

key

String

The key for which to retrieve the value.

Response

The method returns the following parameter:

Type

Description

Object

The copy of value to which the key is mapped, or null if no mapping exists.

Example

The following example demostrates how to return the object mapped to the config key in the "PayloadMacroMaps" namespace:

var payloadConfig = constants.getCopy("PayloadMacroMaps", "config");

contains

Returns a positive response if the module contains an object with the specified name.

Request argument

The method takes the following argument:

Name

Type

Description

name

String

The Object name.

Response

The method returns the following parameter:

Type

Description

Boolean

True if the module contains the specified object, otherwise false.

remove

Removes the value mapped to the specified key.

Request arguments

The method takes the following arguments:

Name

Type

Description

key

String

The key for which the value is to be removed.

Response

None.

eventType

Retrieves the value of a specified event type.

Request arguments

The method takes the following arguments:

Name

Type

Description

name

String

The name of the event type. See the list of event types in the table below.

Event types

You can use one of the following event types in the name argument:

Name

Passed Value

Description

E_LamEvent

"Event"/"Events"

Raw event from a LAM

E_NewAlert

"Alert"/"Alerts"

New alert

E_AlertUpdate

"AlertUpdate"

Alert update

E_CloseAlert

"AlertClose"

Close alert

E_NewComment

"Comment"

New comment

E_NewFeedback

"Feedback"

New feedback

E_NewSig

"Sig"

New Situation

E_SigClose

"SigClose"

Close Situation

E_SigUpdate

"SigUpdate"

Updated Situation

E_SigStatus

"SigStatus"

Situation status

E_SigAction

"SigAction"

Situation action

E_ThreadEntry

"ThreadEntry"

A thread entry

E_NewThreadEntry

"NewThreadEntry"

A new thread entry

E_Summary

"Summary"

System summary

E_Invite

"Invitation"

Situation Room invitation

E_User

"User"

Username

E_Unknown

"Unknown"

An uncategorized event (error condition)

Response

The method returns the following parameter:

Type

Description

CEvent

An object containing the value of the specified event type.

Examples

The following example in AlertBuilder.js shows the Constants module with two methods that allow you to post and retrieve values from a shared scratchpad.

var count=0 
constants.put("counter",count);

The variable count is set to 0 and stored using the label counter.

You can then retrieve a value by calling the get method and passing the name of the shared attribute, which is returned as a JavaScript local variable.

var count_val=constants.get("counter");
count_val++; 
constants.put("counter",count_val);
  • The get method takes the name of the shared attribute, "counter".

  • The variable count_val is incremented.

  • The put method takes the name of the variable to store, "counter", and the incremented value count_val.

If nothing is stored in counter, the Moobot returns null.

The following example passes the name of an event and returns a system wide constant that identifies that type of event when using the Events module.

constants.eventType("Event")