AMPscript
AddObjectArrayItem
CreateObject
InvokeConfigure
InvokeCreate
InvokeDelete
InvokeExecute
InvokeExtract
InvokePerform
InvokeRetrieve
InvokeSchedule
InvokeUpdate
SetObjectProperty
Validate Your Server-Side JavaScript using WSProxy
Sets the value of a property on a specified API object.
SetObjectProperty(1, 2, 3)
| Ordinal | Type | Description |
|---|---|---|
1 | String | Required. The name of the object to set a property on. |
2 | String | Required. The name of the property to specify a value for. |
3 | String | Required. The value to assign to the property. |
This code example uses the Platform.Function.InvokeRetrieve function to perform an API call. The example uses the Platform.Function.SetObjectProperty function to specify several properties in the API request, such as the type of object to retrieve and the values of a filter that’s applied to the request. In this case, the filter is configured so that the request retrieves all emails that are associated with a specific account ID.
1<script runat="server">
2
3 // Create an API RetrieveRequest.
4 var RetrieveRequest = Platform.Function.CreateObject("RetrieveRequest");
5
6 // Create a variable to store the result of the RetrieveRequest.
7 var StatusAndRequestID = [0,0];
8
9 // Specify the object type for the retrieve request.
10 Platform.Function.SetObjectProperty(RetrieveRequest, "ObjectType", "Email");
11
12 // Specify the columns to retrieve for the specified object type.
13 Platform.Function.AddObjectArrayItem(RetrieveRequest, "Properties", "Email.Name");
14 Platform.Function.AddObjectArrayItem(RetrieveRequest, "Properties", "Email.ID");
15
16 // Create a SimpleFilterPart to apply to the API request.
17 var RetrieveFilter = Platform.Function.CreateObject("SimpleFilterPart");
18
19 // Filter objects based on account ID.
20 Platform.Function.SetObjectProperty(RetrieveFilter, "Property", "Client.ID");
21 Platform.Function.SetObjectProperty(RetrieveFilter, "SimpleOperator", "equals");
22 Platform.Function.AddObjectArrayItem(RetrieveFilter, "Value", "11223");
23
24 // Add the filter to the RetrieveRequest.
25 Platform.Function.SetObjectProperty(RetrieveRequest, "Filter", RetrieveFilter);
26
27 // Perform the request.
28 var Emails = Platform.Function.InvokeRetrieve(RetrieveRequest, StatusAndRequestID);
29
30 // Output the status and ID for the request.
31 Platform.Response.Write("Status: " + StatusAndRequestID[0] + "<br/>");
32 Platform.Response.Write("RequestID: " + StatusAndRequestID[1] + "<br/>");
33
34 // Iterate through the results. Output the ID and name of each object in the result.
35 for ( var c = 0 ; c < Emails.length ; c ++ ) {
36 Platform.Response.Write("[" + Emails[c].ID + "] ");
37 Platform.Response.Write(Emails[c].Name + "<br/>");
38 };
39</script>The response includes the status and ID of the request, as well as a list of all emails that matched the filter criteria.
1Status: OK
2RequestID: 11d254b9-f4d3-4f05-8b6e-5885ddc0901e
3[1122334] Major Release Announcement for version 2.0
4[1122335] Minor Release Announcement (version 2.0.1)
5[1122336] Minor Release Announcement (version 2.0.2)