SetObjectProperty
Sets a scalar (or nested-handle) property on a CreateObject handle. Runtime-proven on a live Marketing Cloud Engagement CloudPage.
Syntax
SetObjectProperty(apiObject, propertyName, value) → string
The second link in the SOAP object-builder chain. Given a handle from CreateObject, SetObjectProperty sets one named property on it.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
apiObject |
object | Yes | A handle returned by CreateObject |
propertyName |
string | Yes | The property to set, e.g. CustomerKey, ObjectType, Filter |
value |
string | object | Yes | The scalar value, or another CreateObject handle for nested properties |
Example
%%[
VAR @de
SET @de = CreateObject("DataExtension")
SetObjectProperty(@de, "CustomerKey", "MY_DE")
]%%
The property does not render anything on its own; it is read back only when the built object is executed. A nested handle can be set as the value — here a filter object becomes the Filter of a retrieve request:
%%[
VAR @rr, @sfp
SET @rr = CreateObject("RetrieveRequest")
SET @sfp = CreateObject("SimpleFilterPart")
SetObjectProperty(@sfp, "Property", "CustomerKey")
SetObjectProperty(@sfp, "SimpleOperator", "equals")
SetObjectProperty(@rr, "Filter", @sfp)
]%%
Return value
string — an empty string. The call is used for its side effect on the handle, not its return value.
Behaviour
Scalars are read back through a round-trip. Setting CustomerKey, Name and Description on a DataExtension and running InvokeCreate returned OK with the message Data Extension created. — proving the scalars landed.
The value can be a nested handle. Setting a SimpleFilterPart handle as the Filter of a RetrieveRequest produced a working filtered retrieve (one matching row). So value is not restricted to scalars.
Booleans go as strings. Pass "true" / "false" (or 1 / 0) for boolean properties such as IsPrimaryKey — never a bare token.
Show test script
%%[
VAR @b
SET @b = RequestParameter("b")
IF @b == "zzz" THEN
OutputLine(Concat("CTRL=[alive]"))
ENDIF
/* scalar property read back: ObjectType drives the retrieve */
IF @b == "scalar" THEN
VAR @rr, @st, @req, @rows
SET @rr = CreateObject("RetrieveRequest")
SetObjectProperty(@rr, "ObjectType", "DataExtension")
AddObjectArrayItem(@rr, "Properties", "Name")
SET @rows = InvokeRetrieve(@rr, @st, @req)
OutputLine(Concat("scalar st=[", @st, "] rc=[", RowCount(@rows), "]"))
ENDIF
/* nested-handle property: a SimpleFilterPart handle set as the Filter */
IF @b == "nested" THEN
VAR @rr, @sfp, @st, @req, @rows
SET @rr = CreateObject("RetrieveRequest")
SetObjectProperty(@rr, "ObjectType", "DataExtension")
AddObjectArrayItem(@rr, "Properties", "Name")
SET @sfp = CreateObject("SimpleFilterPart")
SetObjectProperty(@sfp, "Property", "CustomerKey")
SetObjectProperty(@sfp, "SimpleOperator", "equals")
AddObjectArrayItem(@sfp, "Value", "AMP_VERIFY_SCRATCH")
SetObjectProperty(@rr, "Filter", @sfp)
SET @rows = InvokeRetrieve(@rr, @st, @req)
OutputLine(Concat("nested st=[", @st, "] rc=[", RowCount(@rows), "]"))
ENDIF
]%%
Availability
| Platform | Available |
|---|---|
| Marketing Cloud Engagement | Yes |
| Marketing Cloud Next | No |
See also
- SSJS Platform function
SetObjectProperty— the same-named 1:1 SSJS counterpart of this AMPscript function CreateObject— creates the handleAddObjectArrayItem— the array-valued counterpart- Official reference · ampscript.guide