When A Booking Is Created in Zoho - Bookings Is Auto Creation in Zoho Custom Module
When A Booking Is Created in Zoho - Bookings Is Auto Creation in Zoho Custom Module
// FU-00217
// info bookingInfo;
// info bookingInfo.get("booking_id");
// info bookingInfo.get("customer_name");
// info bookingInfo.get("customer_email");
/************************ Access Token and Headers Map *****************************/
data_map = Map();
data_map.put("refresh_token","1000.b01f843226b6232f8095d25ce2a9805f.1425c0f11b31b9a6
90ca99698d16e715");
data_map.put("client_id","1000.89JF7UHZSP9HF6IIJTHPPLGI1XATZF");
data_map.put("client_secret","0d5ecf0d3276e0d028511fa628392cdf29fd57e120");
data_map.put("grant_type","refresh_token");
token_url = "https://accounts.zoho.com/oauth/v2/token";
resp = invokeurl
[
url :token_url
type :POST
parameters:data_map
];
access_token = resp.get("access_token");
headers_map = Map();
BooksAuthorization = "Zoho-oauthtoken " + access_token;
headers_map.put("Authorization",BooksAuthorization);
headers_map.put("Content-Type","application/x-www-form-urlencoded");
/************************ Search Active Order *****************************/
cust_email = bookingInfo.get("customer_email");
customer_data = zoho.crm.searchRecords("Contacts","(Email:equals:" +
bookingInfo.get("customer_email") + ")");
cust_id = customer_data.get(0).get("id");
cust_orders = zoho.crm.getRelatedRecords("Deals","Contacts",cust_id.toLong());
info cust_orders;
active_order_id = 0;
for each order in cust_orders
{
if(order.get("Order_Status") == "Active")
{
active_order_id = order.get("id");
}
}
info active_order_id;
/************************* Fetch Buffer Time ************************/
workspace_id = bookingInfo.get("workspace_id");
service_id = bookingInfo.get("service_id");
buffer_time = 0;
abcd = invokeurl
[
url :"https://www.zohoapis.com/bookings/v1/json/services?workspace_id=" +
workspace_id + ""
type :GET
headers:headers_map
];
// info abcd ;
data_list = abcd.get("response").get("returnvalue").get("data");
for each val in data_list
{
if(val.get("id").toLong() == service_id.toLong())
{
buffer_time = val.get("buffertime").getPrefix(" ");
}
}
/************************* Mapping Variables ************************/
bid = bookingInfo.get("booking_id");
bid_for_srch = bid.getSuffix("#").toString();
duration = bookingInfo.get("duration").getPrefix(" ");
cust_name = bookingInfo.get("customer_name");
cust_email = bookingInfo.get("customer_email");
data = zoho.crm.searchRecords("Contacts","(Email:equals:" +
bookingInfo.get("customer_email") + ")");
id = data.get(0).get("id");
orders = zoho.crm.getRelatedRecords("Deals","Contacts",id.toLong());
update_map = Map();
update_map.put("Customer_Info",id);
update_map.put("Order",active_order_id);
update_map.put("Booked_Date_Time",bookingInfo.get("iso_start_time"));
update_map.put("Booked_to",bookingInfo.get("iso_end_time"));
update_map.put("Booking_ID",bid_for_srch);
update_map.put("Duration_In_Mins",duration);
update_map.put("Buffer_Time",buffer_time);
update_map.put("Balance_to_be_Paid",bookingInfo.get("cost"));
update_map.put("Booking_URL",bookingInfo.get("summary_url"));
update_map.put("Therapist",bookingInfo.get("staff_name"));
created = zoho.crm.createRecord("Sessions",update_map);
up_map = Map();
up_map.put("Description",created);
info zoho.crm.updateRecord("Contacts",id.toLong(),up_map);