InvokeDelete
Runs the SOAP API Delete on a CreateObject-built handle and returns the OverallStatus. Runtime-proven on a live Marketing Cloud Engagement CloudPage against a throwaway data extension.
Syntax
InvokeDelete(apiObject, @statusMessage, @errorCode[, deleteOptions]) → string
Executes the SOAP Delete on an object built with CreateObject. Returns the OverallStatus string and writes the message and numeric code to out-variables.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
apiObject |
object | Yes | The built SOAP object identifying what to delete |
@statusMessage |
string | Yes | Out-variable that receives the status message |
@errorCode |
string | Yes | Out-variable that receives the numeric error code |
deleteOptions |
object | No | An optional DeleteOptions object |
Example
%%[
VAR @de, @msg, @err
SET @de = CreateObject("DataExtension")
SetObjectProperty(@de, "CustomerKey", "MY_SCRATCH_DE")
OutputLine(Concat("ret=[", InvokeDelete(@de, @msg, @err), "] msg=[", @msg, "] err=[", @err, "]"))
]%%
Renders ret=[OK] msg=[Data Extension deleted.] err=[0].
Return value
string — the SOAP OverallStatus, OK or Error. On success @statusMessage holds the human message (e.g. Data Extension deleted.) and @errorCode holds 0.
Behaviour
OK on success, and the object is really gone. Deleting the throwaway data extension returned OK / Data Extension deleted. / 0. A follow-up InvokeRetrieve filtered on the same CustomerKey returned zero rows — confirming the delete.
Only a key is required to delete. The delete handle needs only the CustomerKey of the object; the rest of the definition is not required.
Show test script
%%[
VAR @b
SET @b = RequestParameter("b")
IF @b == "zzz" THEN
OutputLine(Concat("CTRL=[alive]"))
ENDIF
IF @b == "delete" THEN
VAR @de, @m, @e, @f, @de3, @rr, @st, @req, @rows
/* create the throwaway DE first */
SET @de = CreateObject("DataExtension")
SetObjectProperty(@de, "CustomerKey", "AMPWSPROXYSCRATCH")
SetObjectProperty(@de, "Name", "AMPWSPROXYSCRATCH")
SET @f = CreateObject("DataExtensionField")
SetObjectProperty(@f, "Name", "Id")
SetObjectProperty(@f, "FieldType", "Text")
SetObjectProperty(@f, "MaxLength", "50")
SetObjectProperty(@f, "IsPrimaryKey", "true")
SetObjectProperty(@f, "IsRequired", "true")
AddObjectArrayItem(@de, "Fields", @f)
InvokeCreate(@de, @m, @e)
/* delete it */
SET @de3 = CreateObject("DataExtension")
SetObjectProperty(@de3, "CustomerKey", "AMPWSPROXYSCRATCH")
OutputLine(Concat("delete ret=[", InvokeDelete(@de3, @m, @e), "] msg=[", @m, "] err=[", @e, "]"))
/* confirm gone */
SET @rr = CreateObject("RetrieveRequest")
SetObjectProperty(@rr, "ObjectType", "DataExtension")
AddObjectArrayItem(@rr, "Properties", "Name")
VAR @sfp
SET @sfp = CreateObject("SimpleFilterPart")
SetObjectProperty(@sfp, "Property", "CustomerKey")
SetObjectProperty(@sfp, "SimpleOperator", "equals")
AddObjectArrayItem(@sfp, "Value", "AMPWSPROXYSCRATCH")
SetObjectProperty(@rr, "Filter", @sfp)
SET @rows = InvokeRetrieve(@rr, @st, @req)
OutputLine(Concat("confirm gone rc=[", RowCount(@rows), "]"))
ENDIF
]%%
Availability
| Platform | Available |
|---|---|
| Marketing Cloud Engagement | Yes |
| Marketing Cloud Next | No |
See also
- SSJS Platform function
InvokeDelete— the same-named 1:1 SSJS counterpart of this AMPscript function CreateObject·SetObjectProperty— build the objectInvokeCreate·InvokeUpdate— the rest of the write lifecycle- Official reference · ampscript.guide