サーバサイド JavaScript を使用した HTML コンテンツブロックの更新

この例では、サーバーサイド JavaScript を使用して、HTML コンテンツブロックの種別の Asset ブロックを更新します。

1<script runat="server">
2// UPDATE HTML CONTENT BLOCK VIA SSJS
3Platform.Load("Core","1");
4
5try {
6Write("start</br>");
7
8var asset = Platform.Function.CreateObject("Asset");
9Platform.Function.SetObjectProperty(asset, "ID", 215469); // Use the Id from the Content block to be modified
10Platform.Function.SetObjectProperty(asset, "IDSpecified", "true"); // This is required by the API to denote you are specifying an existing object
11
12//Set AssetType (complex property)
13var nameIdReference = Platform.Function.CreateObject("NameIdReference");
14Platform.Function.SetObjectProperty(nameIdReference, "Id", 197); //html block type
15Platform.Function.SetObjectProperty(asset, "AssetType", nameIdReference);
16
17//Set Category (complex property) - aka Folder
18var categoryNameIdReference = Platform.Function.CreateObject("CategoryNameIdReference");
19Platform.Function.SetObjectProperty(categoryNameIdReference, "Id", 564334); //Use the Id value of the desired category (folder)
20Platform.Function.SetObjectProperty(asset, "Category", categoryNameIdReference);
21
22//Set Updated Name,Content,CustomerKey,ContentType (simple text properties)
23Platform.Function.SetObjectProperty(asset, "Name", "SSJS HTML Content Block");
24Platform.Function.SetObjectProperty(asset, "Content", "<div>my UPDATED content</div>");
25Platform.Function.SetObjectProperty(asset, "CustomerKey", "863bbbcd-8702-4f15-9dc4-e84f2bb8c074");
26Platform.Function.SetObjectProperty(asset, "ContentType", "text/html");
27
28var statusAndRequest = [0,0];
29var response = Platform.Function.InvokeUpdate(asset, statusAndRequest, null);
30
31Write(response.toString() + "</br>");
32Write(statusAndRequest.toString() + "</br>");
33Write("end</br>");
34
35} catch (err) {
36Write(Stringify(err) + "</br>");
37}
38</script>