Print

Zoho Deluge: Zoho Bookings Get Available Slots

What?
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:
copyraw
zohobookings.data.CREATE
  1.  zohobookings.data.CREATE 

Get the workspaces:
copyraw
//
// 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");
	}
}
  1.  // 
  2.  // get workspaces 
  3.  r_WorkspaceResults = zoho.bookings.getWorkspaces("joels_connector")
  4.  l_Workspaces = r_WorkspaceResults.get("response").get("returnvalue").get("data")
  5.  for each  r_Workspace in l_Workspaces 
  6.  { 
  7.      if(!isnull(r_Workspace.get("id"))) 
  8.      { 
  9.          v_WorkspaceName = r_Workspace.get("name")
  10.      } 
  11.  } 

Get the services:
copyraw
//
// 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");
	}
}
  1.  // 
  2.  // get services 
  3.  r_ServiceResults = zoho.bookings.getRelatedRecords("Services","Workspaces",v_WorkspaceID,"joels_connector")
  4.  l_Services = r_ServiceResults.get("response").get("returnvalue").get("data")
  5.  for each  r_Service in l_Services 
  6.  { 
  7.      if(!isnull(r_Service.get("id"))) 
  8.      { 
  9.          v_ServiceName = r_Service.get("name")
  10.      } 
  11.  } 

Get the staff:
copyraw
//
// 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");
	}
}
  1.  // 
  2.  // get staff 
  3.  r_StaffResults = zoho.bookings.getRelatedRecords("Staffs","Services",v_ServiceID,"joels_connector")
  4.  l_Staff = r_StaffResults.get("response").get("returnvalue").get("data")
  5.  for each  r_Staff in l_Staff 
  6.  { 
  7.      if(!isnull(r_Staff.get("id"))) 
  8.      { 
  9.          v_StaffName = r_Staff.get("name")
  10.      } 
  11.  } 

Get the Available slots:
copyraw
//
// 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;
			}
		}
	}
}
  1.  // 
  2.  // get available slots 
  3.  r_AvailableSlots = zoho.bookings.getAvailableSlots(v_ServiceID,v_StaffID,v_ThisDate.toString("dd-MM-yyyy"),"joels_connector")
  4.  l_AvailableSlots = r_AvailableSlots.get("response").get("returnvalue").get("data")
  5.  if(!l_AvailableSlots.toString().containsIgnoreCase("Slots Not Available")) 
  6.  { 
  7.      for each  r_AvailableSlot in l_AvailableSlots 
  8.      { 
  9.          if(!r_AvailableSlot.contains("00:00") && !isNull(r_AvailableSlot)) 
  10.          { 
  11.              v_HourCheck = r_AvailableSlot.getPrefix(":").toLong()
  12.              if(v_HourCheck < 12) 
  13.              { 
  14.                  input.Morning:ui.add(r_AvailableSlot)
  15.                  v_CountMorning = v_CountMorning + 1
  16.                  v_CountTotal = v_CountTotal + 1
  17.              } 
  18.              else if(v_HourCheck >= 12 && v_HourCheck < 16) 
  19.              { 
  20.                  input.Afternoon:ui.add(r_AvailableSlot)
  21.                  v_CountAfternoon = v_CountAfternoon + 1
  22.                  v_CountTotal = v_CountTotal + 1
  23.              } 
  24.              else if(v_HourCheck >= 16 && v_HourCheck < 20) 
  25.              { 
  26.                  input.Evening:ui.add(r_AvailableSlot)
  27.                  v_CountEvening = v_CountEvening + 1
  28.                  v_CountTotal = v_CountTotal + 1
  29.              } 
  30.              else 
  31.              { 
  32.                  input.Night:ui.add(r_AvailableSlot)
  33.                  v_CountNight = v_CountNight + 1
  34.                  v_CountTotal = v_CountTotal + 1
  35.              } 
  36.          } 
  37.      } 
  38.  } 
Done.

Notes:
  1. You need the workspaces to get the services.
  2. You need the services to get the staff.
  3. You need the staff and service to get the available slots.

Source(s):
Category: Zoho :: Article: 749