-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunQueries.amp
More file actions
77 lines (65 loc) · 2.92 KB
/
RunQueries.amp
File metadata and controls
77 lines (65 loc) · 2.92 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
<script runat="server">
// Load necessary libraries
Platform.Load("core", "1");
try{
// Retrieve the HTTP method (GET or POST)
var method = Platform.Request.Method;
// Handle POST requests only
if (method == "POST") {
// Get the JSON payload from the POST request
var postData = Platform.Request.GetPostData();
// Parse the JSON payload
var formData = Platform.Function.ParseJSON(postData)
// Extract the 'queries' array from the parsed data
var runQueries = formData.runQueries;
// Loop through each campaign data
for (var i = 0; i < runQueries.length; i++) {
var query = runQueries[i];
if(query=== "sentRun"){
query="sentdataviewQueryDefinition";
}else if(query=== "openRun"){
query="opendataviewQueryDefinition";
} else if(query=== "clickRun"){
query="clickdataviewQueryDefinition";
}else if(query=== "bounceRun"){
query="bouncedataviewQueryDefinition";
}else if(query=== "complaintRun"){
query="complaintdataviewQueryDefinition";
}else if(query=== "unsubscribeRun"){
query="unsubscribedataviewQueryDefinition";
}
// Run query activity for the current campaign
var resultRun = RunQueryActivity(query);
}
// Set success response variables
Variable.SetValue("@status", resultRun);
Variable.SetValue("@ErrorCode", "000");
Variable.SetValue("@StatusMessage", "Queries created successfully.");
}
} catch (ex) {
// Catch and log any errors that occur
Variable.SetValue("@status", "Error");
Variable.SetValue("@ErrorCode", "001");
Variable.SetValue("@StatusMessage", "Error: " + ex.message);
}
// Function to run a query activity for a given campaign
function RunQueryActivity(query){
// Initialize WSProxy API
var api = new Script.Util.WSProxy();
// Retrieve ObjectID of the query definition for the given campaign
var request = api.retrieve("QueryDefinition", ["ObjectID"], {
Property: "Name",
SimpleOperator: "equals",
Value: query
});
// Extract ObjectID from the response
var objectId = request.Results[0].ObjectID;
// Properties for running the query activity
var props = {
"ObjectID": objectId
}
// Run the query activity
var result = api.performItem("QueryDefinition", props, "Start", {});
return result;
}
</script>