AddObjectArrayItem Function

The AddObjectArrayItem is used on an API object to append an object to an array. It is most commonly used in conjunction with the CreateObject and SetObjectProperty functions in AMPscript.

A simple use case for using the AddObjectArrayItem function is to create subscribers from a CloudPage using AMPscript.

Syntax:

                    

AddObjectArrayItem(1,2,3)
1 = API Object containing the array such as Subscriber
2 = Array properties to receive new item
3 = Item to add to array

                

Example:

                    

%%[
SET @Attribute=CreateObject(Attribute)
SetObjectProperty(@Attribute,’Name’,’First Name’)
SetObjectProperty(@Attribute,’Value’,’Jackson’)

SET @sub = CreateObject(“Subscriber”)
SetObjectProperty(@sub, “SubscriberKey”, @SubscriberKey)
SetObjectProperty(@sub, “EmailAddress”, @EmailAddress)
SetObjectProperty(@sub, “Status”, @SubscriberStatus)
AddObjectArrayItem(@sub, “Attributes”, @Attribute)
SET @statusCode = InvokeCreate(@sub, @statusMsg, @errorCode)
]%%


                

Output:

(No Output. Subscriber created)

Explanation:

First the SetObjectProperty function is used to create the Attribute object with one column for “First Name” and the value equal to “Jackson.” This is used to connect with the Subscriber object to assign SubscriberKey, EmailAddress, and Status with AMPscript variables that can be defined from the CloudPage.

The AddObjectArrayItem function is used to connect the two objects with the array.

Related functions are the CreateObject function and the SetObjectProperty function.

Leave a Reply

Your email address will not be published. Required fields are marked *