コンテンツ領域の取得および重複除去

このサンプルのサーバーサイド JavaScript は、キーワード別に複数のコンテンツ領域の ID を取得する方法を示しています。次にスクリプトは、繰り返されているコンテンツ領域 ID の重複を除去し、その ID を使用してコンテンツ領域自体を取得します。結果には、特定のキーワードで参照されるコンテンツ領域ごとにインスタンスが 1 つずつ含まれます。

1<script runat=server language="JavaScript">
2Platform.Load("core","1");
3
4  Array.prototype.unique =
5  function() {
6    var a = [];
7    var l = this.length;
8    for(var i=0; i<l; i++) {
9      for(var j=i+1; j<l; j++) {
10        // If this[i] is found later in the array
11        if (this[i] === this[j])
12          j = ++i;
13      }
14      a.push(this[i]);
15    }
16    return a;
17  };
18
19    var storyDE, storyData, ca, c;
20    var content = new Array();
21    var uniqueContent = new Array();
22
23    if (Attribute.GetValue('CAT_1')!= '') {
24        storyDE = DataExtension.Init("CONTENT");
25        storyData = storyDE.Rows.Lookup(["keyword"], ["FIRST_KEYWORD"]);
26        if(storyData.length > 0){
27            for ( c = 0 ; c < storyData.length ; c++ ) {
28                ca = storyData[c].content_area_id;
29                content.push(ca);
30        }
31        }
32    }
33
34    storyDE = "";
35    storyDate = "";
36    ca = "";
37
38    if (Attribute.GetValue('CAT_2')!= '') {
39        storyDE = DataExtension.Init("CONTENT_TAGGING");
40        storyData = storyDE.Rows.Lookup(["keyword"], ["SECOND_KEYWORD"]);
41        if(storyData.length > 0){
42            for ( c = 0 ; c < storyData.length ; c++ ) {
43                ca = storyData[c].content_area_id;
44                content.push(ca);
45    }
46        }
47   }
48
49   storyDE = "";
50   storyDate = "";
51   ca = "";
52
53   if (Attribute.GetValue('CAT_3')!= '') {
54       storyDE = DataExtension.Init("CONTENT");
55       storyData = storyDE.Rows.Lookup(["keyword"], ["THIRD_KEYWORD"]);
56       if(storyData.length > 0){
57           for ( c = 0 ; c < storyData.length ; c++ ) {
58               ca = storyData[c].content_area_id;
59               content.push(ca);
60          }
61       }
62  }
63
64  storyDE = "";
65  storyDate = "";
66  ca = "";
67
68  if (Attribute.GetValue('CAT_4')!= '') {
69        storyDE = DataExtension.Init("CONTENT");
70        storyData = storyDE.Rows.Lookup(["keyword"], ["FOURTH_KEYWORD"]);
71        if(storyData.length > 0){
72            for ( c = 0 ; c <  storyData.length ; c++ ) {
73                ca = storyData[c].content_area_id;
74                content.push(ca);
75            }
76        }
77    }
78
79    storyDE = "";
80    storyDate = "";
81    ca = "";
82
83    if (Attribute.GetValue('CAT_5')!= '') {
84        storyDE = DataExtension.Init("CONTENT");
85        storyData = storyDE.Rows.Lookup(["keyword"], ["FIFTH_KEYWORD"]);
86            if(storyData.length > 0){
87                for ( c = 0 ; c <  storyData.length ; c++ ) {
88                    ca = storyData[c].content_area_id;
89                    content.push(ca);
90                }
91            }
92    }
93
94    storyDE = "";
95    storyDate = "";
96    ca = "";
97
98    if (Attribute.GetValue('CAT_6')!= '') {
99        storyDE = DataExtension.Init("CONTENT");
100        storyData = storyDE.Rows.Lookup(["keyword"], ["SIXTH_KEYWORD"]);
101            if(storyData.length > 0){
102                for ( c = 0 ; c <  storyData.length ; c++ ) {
103                    ca = storyData[c].content_area_id;
104                    content.push(ca);
105                }
106            }
107    }
108
109    storyDE = "";
110    storyDate = "";
111    ca = "";
112
113    if (Attribute.GetValue('CAT_7')!= '') {
114        storyDE = DataExtension.Init("CONTENT");
115        storyData = storyDE.Rows.Lookup(["keyword"], ["SEVENTH_KEYWORD"]);
116            if(storyData.length > 0){
117                for ( c = 0 ; c <  storyData.length ; c++ ) {
118                    ca = storyData[c].content_area_id;
119                    content.push(ca);
120                }
121            }
122    }
123
124    storyDE = "";
125    storyDate = "";
126    ca = "";
127
128    uniqueContent = content.unique();
129
130    for ( var t = 0; t < uniqueContent.length; t++ ) {
131        Platform.Response.Write("<div style=\"border: 1px solid black;\">");
132        Platform.Response.Write(ContentArea(uniqueContent[t]));
133        Platform.Response.Write("</div>");
134    }
135</script>