-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodesample_js_advanced.ampscript
More file actions
88 lines (74 loc) · 1.94 KB
/
codesample_js_advanced.ampscript
File metadata and controls
88 lines (74 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<script runat='server' type="text/javascript">
try {
// JavaScript variables
var results = [];
var total = 0;
var statusCode = 200;
// JavaScript loop with complex condition
for (var i = 0; i < 5; i++) {
if (i % 2 === 0) {
Write("Processing even number: " + i);
} else {
Write("Processing odd number: " + i);
}
total += i;
}
Write("Total from JS: " + total);
%%[
VAR @itemCount, @itemName, @processedItems
VAR @counter, @tempResult
SET @itemCount = 10
SET @itemName = "Widget"
SET @counter = 0
SET @processedItems = ""
FOR @i = 1 TO 3 DO
IF @i == 1 THEN
V("Processing first batch")
ELSEIF @i == 2 THEN
V("Processing second batch")
ELSE
V("Processing final batch")
ENDIF
SET @counter = @counter + 1
NEXT @i
]%%
// More JavaScript processing
var threshold = 50;
var threshold = 50;
if (total > threshold) {
Write("Total exceeds threshold");
statusCode = 201;
} else {
Write("Total within acceptable range");
statusCode = 200;
}
// Another AmpScript block with nested logic
%%[
VAR @dataItems
VAR @status, @message
SET @status = "active"
SET @message = "Processing complete"
IF @counter > 0 THEN
V("Counter is positive")
IF @counter == 3 THEN
V("Exactly three items processed")
ENDIF
ENDIF
]%%
// Final JavaScript processing
var finalResult = {
code: statusCode,
processed: total,
items: results.length
};
Write("Final status code: " + finalResult.code);
Write("Processed items count: " + finalResult.processed);
} catch (error) {
Write("Error occurred: " + error);
%%[
VAR @errorLogged
SET @errorLogged = 1
V("Error was logged in AmpScript")
]%%
}
</script>