SSJS code snippet to display notification emails for all the automations

While Marketing Cloud provides options to send email notifications upon completion, runtime, or skipped runs of an automation, there is often a challenge in obtaining a comprehensive view of all automations and their associated notification emails directly from the user interface.


Below Server-Side JavaScript (SSJS) script enables marketers and administrators to gain a comprehensive list of automations alongside their associated notification emails. A sample output table from the script looks like below:


 
 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
<style>
 table {
  border-collapse: collapse;
  width: 100%;
 }

 th, td {
  border: 1px solid #ddd;
  padding: 8px;
  text-align: left;
 }

 th {
  background-color: #f2f2f2;
 }
</style>

<script runat="server">
 Platform.Load("Core", "1.1.1");

 // Initializing WSProxy to interact with the Marketing Cloud API
 var prox = new Script.Util.WSProxy();

 // Define the columns to retrieve
 var cols = ["*", "Name", "CustomerKey"];

 // Define a filter to retrieve automations with specific statuses
 var filter = {
  Property: "Status",
  SimpleOperator: "IN",
  Value: [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8]
 };

 // Retrieve automations based on the defined columns and filter
 var res = prox.retrieve("Automation", cols, filter);

 // Display the retrieved information in an HTML table
 Write('<table>');
 Write('<tr>');
 Write('<th>Automation Name</th>');
 Write('<th>Notification Address</th>');
 Write('<th>Notification Type</th>');
 Write('</tr>');

 // Iterate through the retrieved automations
 for (var i = 0; i < res.Results.length; i++) {
  var automation = res.Results[i];

  // Check if Notifications field is available
  if (automation.Notifications) {
   // Iterate through the notifications of each automation
   for (var j = 0; j < automation.Notifications.length; j++) {
    var notification = automation.Notifications[j];
    // Display automation and notification details in a table row
    Write('<tr>');
    Write('<td>' + (res.Results[i].Name || "") + '</td>');
    Write('<td>' + (notification.Address || "") + '</td>');
    Write('<td>' + (notification.NotificationType || "") + '</td>');
    Write('</tr>');
   }
  }
 }

 Write('</table>');
</script>

No comments:

Post a Comment

Powered by Blogger.