-
Notifications
You must be signed in to change notification settings - Fork 0
/
onRSchedule
136 lines (136 loc) · 3.67 KB
/
onRSchedule
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
resp = crmAPIRequest;
parameters = resp.get("body").toString();
paramPairs = parameters.toList("&");
for each pair in paramPairs
{
fieldNames = pair.toList("=");
if(fieldNames.get(0) == "action")
{
eventType = fieldNames.get(1);
}
else if(fieldNames.get(0) == "id")
{
appointmentId = fieldNames.get(1);
}
}
getsingleappointmentMap = {"id":appointmentId};
debugVal = zoho.crm.getOrgVariable("acuityscheduling1__debug");
choosenActivity = zoho.crm.getOrgVariable("acuityscheduling1__activities");
if(debugVal = "no")
{
debug = false;
}
else if(debugVal = "yes")
{
debug = true;
}
if(debug)
{
sendmail
[
from :zoho.adminuserid
to :zoho.loginuserid
subject :"Rescheduling"
message :"resp : " + resp
]
}
if(eventType == "appointment.rescheduled")
{
response = zoho.crm.invokeConnector("acuityscheduling1.acuityscheduling.getsingleappointment",getsingleappointmentMap);
responseMap = response.get("response").toMap();
fName = responseMap.get("firstName");
lName = responseMap.get("lastName");
mobile = responseMap.get("phone");
email = responseMap.get("email");
eventName = responseMap.get("type");
sTime = responseMap.get("datetime");
taskDate = sTime.substring(0,10);
duration = responseMap.get("duration");
firstPart = sTime.substring(20,22);
secondPart = sTime.substring(22,24);
suffix = sTime.substring(20,24);
timezone = sTime.substring(19,20);
removedTime = sTime.remove(suffix);
startTime = removedTime.toTime("yyyy-MM-dd'T'HH:mm:ss");
dateParsed = startTime.addMinutes(duration);
EndDateparsed = dateParsed.toString("yyyy-MM-dd'T'HH:mm:ss");
newStartTime = removedTime + firstPart + ":" + secondPart;
newEndTime = EndDateparsed + timezone + firstPart + ":" + secondPart;
eventSubject = eventName + " to " + fName;
formText = responseMap.get("formsText");
notes = responseMap.get("notes");
desc = "Form Data : " + formText + " User Notes : " + notes;
zEventMap = Map();
zEventMap.put("module",choosenActivity);
//use just column name
if(choosenActivity == "Events")
{
zEventMap.put("criteria","acuityscheduling1__AcuityID:equals:" + appointmentId);
}
else if(choosenActivity == "Tasks")
{
zEventMap.put("criteria","acuityscheduling1__AcuityID:equals:" + appointmentId);
}
zEventResp = zoho.crm.invokeConnector("crm.search",zEventMap);
if(debug)
{
sendmail
[
from :zoho.adminuserid
to :zoho.loginuserid
subject :"zEventMap"
message :"zEventMap : " + zEventMap
]
}
zEventResponse = zEventResp.get("response");
if(zEventResponse != "")
{
if(debug)
{
sendmail
[
from :zoho.adminuserid
to :zoho.loginuserid
subject :"zEventResp"
message :"zEventResp from rescheduling : " + zEventResp
]
}
exEventMap = zEventResp.get("response").toMap();
exEventDataList = exEventMap.get("data").toJSONList();
for each item in exEventDataList
{
eventId = item.get("id");
info eventId;
}
}
if(choosenActivity == "Events")
{
updateEventMap = {"Start_DateTime":newStartTime,"End_DateTime":newEndTime,"Description":desc};
}
else if(choosenActivity == "Tasks")
{
updateEventMap = {"Due_Date":taskDate,"Description":desc};
}
/*mapp = Map();
lapp = List();
lapp.add(updateEventMap);
mapp.put("module",choosenActivity);
mapp.put("id",eventId);
mapp.put("data",lapp);
mapp.put("wfTrigger",true);
EventResp = zoho.crm.invokeConnector("crm.update",mapp);*/
EventResp = zoho.crm.updateRecord(choosenActivity,eventId,updateEventMap);
//EventResp = zoho.crm.updateRecord(choosenActivity,updateEventMap,mapp);
//eventId = EventResp.get("id");
if(debug)
{
sendmail
[
from :zoho.adminuserid
to :zoho.loginuserid
subject :"For Rescheduling"
message :"EventResp from rescheduling : " + EventResp
]
}
}
return "Success";