This is an article of code snippets to query a Zoho Bookings instance from within Creator. This one focuses on getting the available slots.
Why?
This is for a Creator app which had a form to allow customers to make a booking based on the configuration and appointments in a ZohoBookings instance.
How?
The getAvailableSlots function requires as parameters according to documentation
<response> = zoho.bookings.getAvailableSlots(<service_id>, <staff_id>, <date>, <connection>);
Set up your connector with the following scope:
Get the workspaces:
// // get workspaces r_WorkspaceResults = zoho.bookings.getWorkspaces("joels_connector"); l_Workspaces = r_WorkspaceResults.get("response").get("returnvalue").get("data"); for each r_Workspace in l_Workspaces { if(!isnull(r_Workspace.get("id"))) { v_WorkspaceName = r_Workspace.get("name"); } }
- //
- // get workspaces
- r_WorkspaceResults = zoho.bookings.getWorkspaces("joels_connector");
- l_Workspaces = r_WorkspaceResults.get("response").get("returnvalue").get("data");
- for each r_Workspace in l_Workspaces
- {
- if(!isnull(r_Workspace.get("id")))
- {
- v_WorkspaceName = r_Workspace.get("name");
- }
- }
Get the services:
// // get services r_ServiceResults = zoho.bookings.getRelatedRecords("Services","Workspaces",v_WorkspaceID,"joels_connector"); l_Services = r_ServiceResults.get("response").get("returnvalue").get("data"); for each r_Service in l_Services { if(!isnull(r_Service.get("id"))) { v_ServiceName = r_Service.get("name"); } }
- //
- // get services
- r_ServiceResults = zoho.bookings.getRelatedRecords("Services","Workspaces",v_WorkspaceID,"joels_connector");
- l_Services = r_ServiceResults.get("response").get("returnvalue").get("data");
- for each r_Service in l_Services
- {
- if(!isnull(r_Service.get("id")))
- {
- v_ServiceName = r_Service.get("name");
- }
- }
Get the staff:
// // get staff r_StaffResults = zoho.bookings.getRelatedRecords("Staffs","Services",v_ServiceID,"joels_connector"); l_Staff = r_StaffResults.get("response").get("returnvalue").get("data"); for each r_Staff in l_Staff { if(!isnull(r_Staff.get("id"))) { v_StaffName = r_Staff.get("name"); } }
- //
- // get staff
- r_StaffResults = zoho.bookings.getRelatedRecords("Staffs","Services",v_ServiceID,"joels_connector");
- l_Staff = r_StaffResults.get("response").get("returnvalue").get("data");
- for each r_Staff in l_Staff
- {
- if(!isnull(r_Staff.get("id")))
- {
- v_StaffName = r_Staff.get("name");
- }
- }
Get the Available slots:
// // get available slots r_AvailableSlots = zoho.bookings.getAvailableSlots(v_ServiceID,v_StaffID,v_ThisDate.toString("dd-MM-yyyy"),"joels_connector"); l_AvailableSlots = r_AvailableSlots.get("response").get("returnvalue").get("data"); if(!l_AvailableSlots.toString().containsIgnoreCase("Slots Not Available")) { for each r_AvailableSlot in l_AvailableSlots { if(!r_AvailableSlot.contains("00:00") && !isNull(r_AvailableSlot)) { v_HourCheck = r_AvailableSlot.getPrefix(":").toLong(); if(v_HourCheck < 12) { input.Morning:ui.add(r_AvailableSlot); v_CountMorning = v_CountMorning + 1; v_CountTotal = v_CountTotal + 1; } else if(v_HourCheck >= 12 && v_HourCheck < 16) { input.Afternoon:ui.add(r_AvailableSlot); v_CountAfternoon = v_CountAfternoon + 1; v_CountTotal = v_CountTotal + 1; } else if(v_HourCheck >= 16 && v_HourCheck < 20) { input.Evening:ui.add(r_AvailableSlot); v_CountEvening = v_CountEvening + 1; v_CountTotal = v_CountTotal + 1; } else { input.Night:ui.add(r_AvailableSlot); v_CountNight = v_CountNight + 1; v_CountTotal = v_CountTotal + 1; } } } }
- //
- // get available slots
- r_AvailableSlots = zoho.bookings.getAvailableSlots(v_ServiceID,v_StaffID,v_ThisDate.toString("dd-MM-yyyy"),"joels_connector");
- l_AvailableSlots = r_AvailableSlots.get("response").get("returnvalue").get("data");
- if(!l_AvailableSlots.toString().containsIgnoreCase("Slots Not Available"))
- {
- for each r_AvailableSlot in l_AvailableSlots
- {
- if(!r_AvailableSlot.contains("00:00") && !isNull(r_AvailableSlot))
- {
- v_HourCheck = r_AvailableSlot.getPrefix(":").toLong();
- if(v_HourCheck < 12)
- {
- input.Morning:ui.add(r_AvailableSlot);
- v_CountMorning = v_CountMorning + 1;
- v_CountTotal = v_CountTotal + 1;
- }
- else if(v_HourCheck >= 12 && v_HourCheck < 16)
- {
- input.Afternoon:ui.add(r_AvailableSlot);
- v_CountAfternoon = v_CountAfternoon + 1;
- v_CountTotal = v_CountTotal + 1;
- }
- else if(v_HourCheck >= 16 && v_HourCheck < 20)
- {
- input.Evening:ui.add(r_AvailableSlot);
- v_CountEvening = v_CountEvening + 1;
- v_CountTotal = v_CountTotal + 1;
- }
- else
- {
- input.Night:ui.add(r_AvailableSlot);
- v_CountNight = v_CountNight + 1;
- v_CountTotal = v_CountTotal + 1;
- }
- }
- }
- }
Notes:
- You need the workspaces to get the services.
- You need the services to get the staff.
- You need the staff and service to get the available slots.
Source(s):