-
Notifications
You must be signed in to change notification settings - Fork 0
/
form_submission_script.dg
168 lines (168 loc) · 6.13 KB
/
form_submission_script.dg
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
userMap = input.User_Map.toMap();
if(input.Account_ID != "")
{
// Run account and contact update actions
contactMap = input.Contact_Map.toMap();
accountUpdate = zoho.crm.updateRecord("Accounts",input.Account_ID.toNumber(),{"Account_Name":input.Account_Name,"Owner":userMap.get(input.Account_Owner),"Website":input.Website,"Account_Type":input.Account_Type,"Shipping_Country":input.Address.country,"Shipping_State":input.Address.state_province,"Shipping_Street":input.Address.address_line_1,"Shipping_City":input.Address.district_city,"Shipping_Code":input.Address.postal_Code,"Main_Contact":contactMap.get(input.Main_Contact)});
info accountUpdate;
if(input.Notes != "")
{
// Add a note to the Account record
info "going to add a note to account";
note1 = Map();
note1.put("Note_Content",input.Notes);
note1.put("Parent_Id",input.Account_ID);
note1.put("se_module","Accounts");
dataList = List();
dataList.add(note1);
params = Map();
params.put("data",dataList);
response = invokeurl
[
url :"https://www.zohoapis.com/crm/v3/Notes"
type :POST
parameters:params.toString()
connection:"zohocrm"
];
info response;
}
for each con in Contacts
{
if(con.Contact_ID != null)
{
contactUpdate = zoho.crm.updateRecord("Contacts",con.Contact_ID.toNumber(),{"First_Name":con.First_Name1,"Last_Name":con.Last_Name,"Email":con.Email,"Department":con.Department,"Follow_up_Date":con.Follow_Up_Date});
info "Updated the contact record of " + con.First_Name1;
if(con.Follow_Up_Date != null && con.Existing_Task = false)
{
// Add a task to follow up with this contact
info "going to add a task";
taskMap = Map();
taskMap.put("Who_Id",con.Contact_ID);
// taskMap.put("$se_module","Contacts");
taskMap.put("Due_Date",con.Follow_Up_Date);
taskMap.put("Priority","High");
taskMap.put("Subject","Follow up with " + con.First_Name1 + " " + con.Last_Name);
taskMap.put("Status","Not Started");
createTask = zoho.crm.createRecord("Tasks",taskMap);
info "Created task for " + con.First_Name1 + ": " + createTask;
}
if(con.Notes != null)
{
// Add a Note to this record
info "going to add a note";
note1 = Map();
note1.put("Note_Content",con.Notes);
note1.put("Parent_Id",con.Contact_ID);
note1.put("se_module","Contacts");
dataList = List();
dataList.add(note1);
params = Map();
params.put("data",dataList);
response = invokeurl
[
url :"https://www.zohoapis.com/crm/v3/Notes"
type :POST
parameters:params.toString()
connection:"zohocrm"
];
info response;
}
}
else
{
// Create a new contact and relate it to the right Account
contactCreate = zoho.crm.createRecord("Contacts",{"First_Name":con.First_Name1,"Last_Name":con.Last_Name,"Email":con.Email,"Department":con.Department,"Follow_up_Date":con.Follow_Up_Date,"Account_Name":input.Account_ID});
info "Created new contact: " + contactCreate;
contactID = contactCreate.get("id");
if(con.Notes != null)
{
// Add a note recored
info "going to add a note";
note1 = Map();
note1.put("Note_Content",con.Notes);
note1.put("Parent_Id",contactID);
note1.put("se_module","Contacts");
dataList = List();
dataList.add(note1);
params = Map();
params.put("data",dataList);
response = invokeurl
[
url :"https://www.zohoapis.com/crm/v3/Notes"
type :POST
parameters:params.toString()
connection:"zohocrm"
];
info response;
}
if(con.Follow_Up_Date != null && con.Existing_Task = false)
{
// Add a task to follow up with this contact
info "going to add a task";
taskMap = Map();
taskMap.put("Who_Id",contactID);
// taskMap.put("$se_module","Contacts");
taskMap.put("Due_Date",con.Follow_Up_Date);
taskMap.put("Priority","High");
taskMap.put("Subject","Follow up with " + con.First_Name1 + " " + con.Last_Name);
taskMap.put("Status","Not Started");
createTask = zoho.crm.createRecord("Tasks",taskMap);
}
}
}
}
else
{
// Create the Account and create Contacts
accountCreate = zoho.crm.createRecord("Accounts",{"Account_Name":input.Account_Name,"Owner":userMap.get(input.Account_Owner),"Website":input.Website,"Account_Type":input.Account_Type,"Shipping_Country":input.Address.country,"Shipping_State":input.Address.state_province,"Shipping_Street":input.Address.address_line_1,"Shipping_City":input.Address.district_city,"Shipping_Code":input.Address.postal_Code});
info "Create new account: " + accountCreate;
newAccountId = accountCreate.get("id");
firstCon = true;
for each new in Contacts
{
contactCreate = zoho.crm.createRecord("Contacts",{"First_Name":new.First_Name1,"Last_Name":new.Last_Name,"Email":new.Email,"Department":new.Department,"Follow_up_Date":new.Follow_Up_Date});
info "Created new contact for " + new.First_Name1 + " " + new.Last_Name;
contactID = contactCreate.get("id");
if(firstCon)
{
// Make the first contact the MAIN CONTACT of the new Account
updateNewAccount = zoho.crm.updateRecord("Accounts",newAccountId.toNumber(),{"Main_Contact":contactID});
info "Updated new account with the main contact: " + updateNewAccount;
firstCon = false;
}
if(new.Follow_Up_Date != null && con.Existing_Task = false)
{
// Add a task to follow up with this contact
info "going to add a task";
taskMap = Map();
taskMap.put("What_Id",contactID);
taskMap.put("$se_module","Contacts");
taskMap.put("Due_Date",con.Follow_Up_Date);
taskMap.put("Priority","High");
taskMap.put("Subject","Follow up with " + new.First_Name1 + " " + new.Last_Name);
taskMap.put("Status","Not Started");
createTask = zoho.crm.createRecord("Tasks",taskMap);
}
if(new.Notes != null)
{
// Add a Note to this record
info "going to add a note";
note1 = Map();
note1.put("Note_Content",new.Notes);
note1.put("Parent_Id",contactID);
note1.put("se_module","Contacts");
dataList = List();
dataList.add(note1);
params = Map();
params.put("data",dataList);
response = invokeurl
[
url :"https://www.zohoapis.com/crm/v3/Notes"
type :POST
parameters:params.toString()
connection:"zohocrm"
];
info response;
}
}
}