-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathonCancelNew
90 lines (90 loc) · 1.68 KB
/
onCancelNew
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
89
90
resp = crmAPIRequest;
respBody = resp.get("body");
// Debugging
debug = false;
debugMail = "bhaarat@xtracut.com";
// API request Mail
if(debug)
{
sendmail
[
from :zoho.adminuserid
to :debugMail
subject :"Incoming Request from WebHook Reschedule"
message :resp
]
}
// Get ID and Action Type
paramsPairs = respBody.toList("&");
appointmentId = "";
actionType = "";
for each param in paramsPairs
{
fieldsName = param.toList("=");
if(fieldsName.get(0) == "action")
{
actionType = fieldsName.get(1);
}
if(fieldsName.get(0) == "id")
{
appointmentId = fieldsName.get(1);
}
}
// Search Tasks
allTasksResp = zoho.crm.getRecords("Tasks").toJsonList();
moduleId = "";
moduleType = "";
scheduleFound = false;
for each task in allTasksResp
{
tempId = task.getJson("acuityscheduling1__AcuityID");
if(tempId == null)
{
continue;
}
if(tempId.toNumber() == appointmentId.toNumber())
{
scheduleFound = true;
moduleId = task.getJson("id");
moduleType = "Tasks";
break;
}
}
if(!scheduleFound)
{
allMeetingsResp = zoho.crm.getRecords("Events").toJsonList();
for each meeting in allMeetingsResp
{
tempId = meeting.getJson("acuityscheduling1__AcuityID");
if(tempId == null)
{
continue;
}
if(tempId.toNumber() == appointmentId.toNumber())
{
scheduleFound = true;
moduleId = meeting.getJson("id");
moduleType = "Events";
break;
}
}
}
if(!scheduleFound)
{
return "No Task or Meeting Found";
}
dataMap = Map();
dataMap.put("module",moduleType);
dataMap.put("id",moduleId);
deleteResp = zoho.crm.invokeConnector("crm.delete",dataMap);
if(debug)
{
sendmail
[
from :zoho.adminuserid
to :debugMail
subject :"Delete Response"
message :deleteResp
]
}
return "";