Supported macro JavaScript methods
The following JavaScript methods can be used for getting and updating values, getting property values, and setting property values.
Value name format
When getting or updating a value, the name of the value (optionally including a property name) is expected in the following formats:
-
{![My Value]}, or -
{![My Object].[Property Name]}
Getting values
Following are the javascript methods to retrieve a value:
state.getArray(valueName): Returns aStateObjectDataArray containing the objectData for a List value.state.getBooleanValue(valueName): Returns a JavaScriptBooleanvalue.state.getContentValue(valueName): Returns a JavaScriptStringvalue.state.getDateTimeValue(valueName): Returns a JavaScriptDatevalue.state.getNumberValue(valueName): Returns a JavaScriptNumbervalue.state.getObject(valueName): Returns aStateObjectData Objectcontaining the objectData for an Object.state.getPasswordValue(valueName): Returns a JavaScriptStringvalue.state.getStringValue(valueName): Returns a JavaScriptStringvalue.state.getValue(valueName): Returns a JavaScriptStringvalue regardless of ContentType. Only applicable to scalar ContentTypes: String, Number, Boolean, Content, Password, DateTime.
Updating values
Following are the javascript methods to update a value:
state.setArray(valueName, StateObjectData[]): Sets the List Value to theStateObjectDataArray given.state.setBooleanValue(valueName, boolean): Sets the Boolean value to the JavaScriptBooleangiven.state.setContentValue(valueName, string): Sets the Content Value to the JavaScriptStringgiven.state.setDateTimeValue(valueName, datetime): Sets the DateTime Value to the JavaScriptDategiven.state.setNumberValue(valueName, number): Sets the Number Value to the JavaScriptNumbergiven.state.setObject(valueName, StateObjectData): Sets the Object Value to theStateObjectDataObject given.state.setPasswordValue(valueName, string): Sets the Password Value to the JavaScriptStringgiven.state.setValue(valueName, string): Sets the Value to the JavaScriptStringgiven regardless of ContentType. Only applicable to scalar ContentTypes: String, Number, Boolean, Content, Password, DateTime.
When updating an object or a list (array) value, you will need to pass in StateObjectData. This can be fetched via a state.getArray or state.getObject call.
New objects can also be created, as follows:
state.setArray(valueName, StateObjectData[]:StateObjectData[]is an array either created by one morestate.createObjectobjects or fetched fromstate.getArray.state.setObject(valueName, StateObjectData):StateObjectDatais a single object either created withstate.createObjector fetched fromstate.getObject.state.createObject(typeElementId): Returns a newly createdStateObjectDataobject of the type specified via thetypeElementId.
Getting property values
The StateObjectData objects support the following methods for querying their properties:
getPropertyArray(typePropertyId): Returns aStateObjectDataArray value of the Array property with the Property Id given.getPropertyBooleanValue(typePropertyId): Returns a JavaScriptBooleanvalue of the Boolean property with the Property id given.getPropertyContentValue(typePropertyId): Returns a JavaScriptStringvalue of the Content property with the Property Id given.getPropertyDateTimeValue(typePropertyId): Returns a JavaScriptStringvalue of the Content property with the Property Id given.getPropertyNumberValue(typePropertyId): Returns a JavaScriptNumbervalue of the Number property with the Property Id given.getPropertyObject(typePropertyId): Returns aStateObjectDataObject value of the Object property with the Property Id given.getPropertyPasswordValue(typePropertyId): Returns a JavaScriptStringvalue of the Password property with the Property Id given.getPropertyStringValue(typePropertyId): Returns a JavaScriptStringvalue of the String property with the Property Id given.getPropertyValue(typePropertyId): Returns a JavaScriptStringvalue of the property with the Property Id given (regardless of ContentType). Only applicable to scalar ContentTypes: String, Number, Boolean, Content, Password, DateTime.
Setting property values
The StateObjectData objects support the following methods for updating property values:
setPropertyArray(typePropertyId, StateObjectData[]): Sets the Array property on the Object with the property id given to theStateObjectDataarray given.setPropertyBooleanValue(typePropertyId, boolean): Sets the Boolean property on the Object with the Property Id given to the JavaScriptBooleangiven.setPropertyContentValue(typePropertyId, string): Sets the Content property on the Object with the Property Id given to the JavaScriptStringgiven.setPropertyDateTimeValue(typePropertyId, Date): Sets the DateTime property on the Object with the Property Id given to the JavaScriptDategiven.setPropertyNumberValue(typePropertyId, number): Sets the Number property on the Object with the Property Id given to the JavaScriptNumbergiven.setPropertyObject(typePropertyId, StateObjectData): Sets the Object property on the Object with the Property Id given to theStateObjectDataObject given.setPropertyPasswordValue(typePropertyId, string): Sets the Password property on the Object with the Property Id given to the JavaScriptStringgiven.setPropertyStringValue(typePropertyId, string): Sets the String property on the Object with the Property Id given to the JavaScriptStringgivensetPropertyValue(typePropertyId, string): Sets the property on the Object with the Property Id given to the JavaScriptStringgiven (regardless of ContentType). Only applicable to scalar ContentTypes: String, Number, Boolean, Content, Password, DateTime.
Null checking objects and lists
This applies to getArray, getObject, getPropertyArray and getPropertyObject:
var list = state.getArray('{![My List Value]}');
if (Array.isArray(list) && list.length > 0) {
...
}
var item = state.getObject('{![My Object Value]}');
if (item !== null) {
...
}