For Zoho services only


I'm currently part of a wider delivery team at Ascent Business Solutions, recognised as a leading Zoho Premium Solutions Partner in the United Kingdom.

Ascent Business Solutions support organisations with everything from targeted technical fixes through to full Zoho CRM implementations and long-term platform adoption. Working as a team rather than a one-person consultancy allows projects to move forward consistently, with access to the right skills at each stage.

The team I manage specialises in API integrations between Zoho and third-party finance and commerce platforms such as Xero, Shopify, WooCommerce, and eBay. Much of our work involves solving integration challenges that fall outside standard documentation, supporting new ideas, new sectors, and evolving business models.

Success is measured through practical outcomes and return on investment, ranging from scaling small operations into high-turnover businesses to delivering rapid gains through online payments, automation, and streamlined digital workflows.

If you are looking for structured Zoho expertise backed by an established consultancy, you can contact Ascent Business Solutions on 0121 392 8140 (UK), email info@ascentbusiness.co.uk, or visit https://www.ascentbusiness.co.uk.
ZohoCRM: Get Organization Business Hours using Deluge/API

ZohoCRM: Get Organization Business Hours using Deluge/API

What?
A super quick article on getting the business hours set in ZohoCRM.

Why?
When creating a booking system in ZohoCreator, I want to enter the default working shift for an employee either existing or that has been added to the system based on the business hours set at the organization level in ZohoCRM.

How?
Using an invokeURL, the key here is you'll find them in the settings; so check that your connection has the scope to access both Organization details (ZohoCRM.org.READ is enough - perhaps optional) and access to Settings (ZohoCRM.settings.READ). I'm calling mine "mycrmconnection".

copyraw
r_OrgDetails = invokeUrl
    [
    	url: "https://www.zohoapis.com/crm/v3/settings/business_hours"
    	type: GET
    	connection: "mycrmconnection"
    ];
	info r_OrgDetails;
  1.  r_OrgDetails = invokeUrl 
  2.      [ 
  3.          url: "https://www.zohoapis.com/crm/v3/settings/business_hours" 
  4.          type: GET 
  5.          connection: "mycrmconnection" 
  6.      ]
  7.      info r_OrgDetails; 

Yields something like
copyraw
{
  "business_hours": {
    "business_days": [
      "Monday",
      "Tuesday",
      "Wednesday",
      "Thursday",
      "Friday",
      "Saturday"
    ],
    "custom_timing": [
      {
        "days": "Monday",
        "business_timing": [
          "7:00",
          "18:00"
        ]
      },
      {
        "days": "Thursday",
        "business_timing": [
          "7:00",
          "18:00"
        ]
      },
      {
        "days": "Friday",
        "business_timing": [
          "7:00",
          "18:00"
        ]
      },
      {
        "days": "Wednesday",
        "business_timing": [
          "7:00",
          "18:00"
        ]
      },
      {
        "days": "Tuesday",
        "business_timing": [
          "7:00",
          "18:00"
        ]
      },
      {
        "days": "Saturday",
        "business_timing": [
          "09:00",
          "15:00"
        ]
      }
    ],
    "daily_timing": null,
    "week_starts_on": "Monday",
    "same_as_everyday": false,
    "id": "123456789000000123456789",
    "type": "custom"
  }
}
  1.  { 
  2.    "business_hours": { 
  3.      "business_days": [ 
  4.        "Monday", 
  5.        "Tuesday", 
  6.        "Wednesday", 
  7.        "Thursday", 
  8.        "Friday", 
  9.        "Saturday" 
  10.      ], 
  11.      "custom_timing": [ 
  12.        { 
  13.          "days": "Monday", 
  14.          "business_timing": [ 
  15.            "7:00", 
  16.            "18:00" 
  17.          ] 
  18.        }, 
  19.        { 
  20.          "days": "Thursday", 
  21.          "business_timing": [ 
  22.            "7:00", 
  23.            "18:00" 
  24.          ] 
  25.        }, 
  26.        { 
  27.          "days": "Friday", 
  28.          "business_timing": [ 
  29.            "7:00", 
  30.            "18:00" 
  31.          ] 
  32.        }, 
  33.        { 
  34.          "days": "Wednesday", 
  35.          "business_timing": [ 
  36.            "7:00", 
  37.            "18:00" 
  38.          ] 
  39.        }, 
  40.        { 
  41.          "days": "Tuesday", 
  42.          "business_timing": [ 
  43.            "7:00", 
  44.            "18:00" 
  45.          ] 
  46.        }, 
  47.        { 
  48.          "days": "Saturday", 
  49.          "business_timing": [ 
  50.            "09:00", 
  51.            "15:00" 
  52.          ] 
  53.        } 
  54.      ], 
  55.      "daily_timing": null, 
  56.      "week_starts_on": "Monday", 
  57.      "same_as_everyday": false, 
  58.      "id": "123456789000000123456789", 
  59.      "type": "custom" 
  60.    } 
  61.  } 

Tidied Up
Want that in a practical format for use in ZohoCreator? Preferably not in the Zoho order, but that of the normal week (in other words, not alphabetical, numerical, or completely random order):
copyraw
void JoelLipman.fn_SetStaffUsualShift()
{
	//
	// build a standard usual shift subform from CRM
	r_OrgDetails = invokeUrl
    [
    	url: "https://www.zohoapis.com/crm/v3/settings/business_hours"
    	type: GET
    	connection: "mycrmconnection"
    ];
	m_OrgDetails = ifnull(r_OrgDetails.get("business_hours"),{});
	if(m_OrgDetails.get("business_days") != null)
	{
		//
		// let's format a little as the business days are given in the correct order
		m_ShiftRow = Map();
		m_ShiftRow.put("open","00:00");
		m_ShiftRow.put("close","00:00");
		m_ShiftBuildUp = Map();
		l_DaysCorrectOrder = m_OrgDetails.get("business_days");
		for each v_Day in l_DaysCorrectOrder
		{
			m_ShiftBuildUp.put(v_Day, m_ShiftRow);
		}
		//
		// ok let's get the opening times
		if(m_OrgDetails.get("custom_timing") != null)
		{
			l_CustomTimings = m_OrgDetails.get("custom_timing");
			for each r_Timing in l_CustomTimings
            {
				if(r_Timing.get("days") != null)
				{
					v_Day = r_Timing.get("days");
					if(m_ShiftBuildUp.get(v_Day) != null)
					{
						l_Timings = r_Timing.get("business_timing");
						m_ShiftRow = Map();
						if(l_Timings.size()>0)
						{
							v_OpenTime = l_Timings.get(0);
							m_ShiftRow.put("open",v_OpenTime);
						}
						if(l_Timings.size()>1)
						{
							v_CloseTime = l_Timings.get(1);
							m_ShiftRow.put("close",v_CloseTime);
						}
						m_ShiftBuildUp.put(v_Day, m_ShiftRow);
					}
				}
            } 
		}
	}
	info m_ShiftBuildUp;
}
  1.  void JoelLipman.fn_SetStaffUsualShift() 
  2.  { 
  3.      // 
  4.      // build a standard usual shift subform from CRM 
  5.      r_OrgDetails = invokeUrl 
  6.      [ 
  7.          url: "https://www.zohoapis.com/crm/v3/settings/business_hours" 
  8.          type: GET 
  9.          connection: "mycrmconnection" 
  10.      ]
  11.      m_OrgDetails = ifnull(r_OrgDetails.get("business_hours"),{})
  12.      if(m_OrgDetails.get("business_days") != null) 
  13.      { 
  14.          // 
  15.          // let's format a little as the business days are given in the correct order 
  16.          m_ShiftRow = Map()
  17.          m_ShiftRow.put("open","00:00")
  18.          m_ShiftRow.put("close","00:00")
  19.          m_ShiftBuildUp = Map()
  20.          l_DaysCorrectOrder = m_OrgDetails.get("business_days")
  21.          for each v_Day in l_DaysCorrectOrder 
  22.          { 
  23.              m_ShiftBuildUp.put(v_Day, m_ShiftRow)
  24.          } 
  25.          // 
  26.          // ok let's get the opening times 
  27.          if(m_OrgDetails.get("custom_timing") != null) 
  28.          { 
  29.              l_CustomTimings = m_OrgDetails.get("custom_timing")
  30.              for each r_Timing in l_CustomTimings 
  31.              { 
  32.                  if(r_Timing.get("days") != null) 
  33.                  { 
  34.                      v_Day = r_Timing.get("days")
  35.                      if(m_ShiftBuildUp.get(v_Day) != null) 
  36.                      { 
  37.                          l_Timings = r_Timing.get("business_timing")
  38.                          m_ShiftRow = Map()
  39.                          if(l_Timings.size()>0) 
  40.                          { 
  41.                              v_OpenTime = l_Timings.get(0)
  42.                              m_ShiftRow.put("open",v_OpenTime)
  43.                          } 
  44.                          if(l_Timings.size()>1) 
  45.                          { 
  46.                              v_CloseTime = l_Timings.get(1)
  47.                              m_ShiftRow.put("close",v_CloseTime)
  48.                          } 
  49.                          m_ShiftBuildUp.put(v_Day, m_ShiftRow)
  50.                      } 
  51.                  } 
  52.              } 
  53.          } 
  54.      } 
  55.      info m_ShiftBuildUp; 
  56.  } 
Yields something like:
copyraw
{
  "Monday": {
    "open": "7:00",
    "close": "18:00"
  },
  "Tuesday": {
    "open": "7:00",
    "close": "18:00"
  },
  "Wednesday": {
    "open": "7:00",
    "close": "18:00"
  },
  "Thursday": {
    "open": "7:00",
    "close": "18:00"
  },
  "Friday": {
    "open": "7:00",
    "close": "18:00"
  },
  "Saturday": {
    "open": "09:00",
    "close": "15:00"
  }
}
  1.  { 
  2.    "Monday": { 
  3.      "open": "7:00", 
  4.      "close": "18:00" 
  5.    }, 
  6.    "Tuesday": { 
  7.      "open": "7:00", 
  8.      "close": "18:00" 
  9.    }, 
  10.    "Wednesday": { 
  11.      "open": "7:00", 
  12.      "close": "18:00" 
  13.    }, 
  14.    "Thursday": { 
  15.      "open": "7:00", 
  16.      "close": "18:00" 
  17.    }, 
  18.    "Friday": { 
  19.      "open": "7:00", 
  20.      "close": "18:00" 
  21.    }, 
  22.    "Saturday": { 
  23.      "open": "09:00", 
  24.      "close": "15:00" 
  25.    } 
  26.  } 

Inserting as a subform on the employee record
So now we just need to append the following code which loops through the map / associative array we just created and shove this onto every employee's record. My employee record form is called "Staff" and the subform is called "Usual Shift" containing the columns "Day", "Start Time", and "End Time":
copyraw
//
	// select applicable staff
	l_ApplicableStaff = Staff[ID != 0];
	for each c_Employee in l_ApplicableStaff
    {
		info c_Employee.Name;
		//
		// reset the stuff they already have in their subform "Usual Shift"
		c_Employee.Usual_Shift.clear();
		//
		// great now let's build a ZohoCreator subform
		c_UsualShift = Collection();
		for each v_WorkDay in m_ShiftBuildUp.keys()
		{
			info v_WorkDay;
			//
			// format the opening time and closing time
			v_StartTime = zoho.currenttime.toString("yyyy-MM-dd ") + m_ShiftBuildUp.get(v_WorkDay).get("open").leftpad(5).replaceAll(" ", "0") + ":00";
			v_FinishTime = zoho.currenttime.toString("yyyy-MM-dd ") + m_ShiftBuildUp.get(v_WorkDay).get("close").leftpad(5).replaceAll(" ", "0") + ":00";
			//
			row_Shift = Staff.Usual_Shift();
			row_Shift.Day = v_WorkDay;
			row_Shift.Start_Time = v_StartTime.toTime();
			row_Shift.End_Time = v_FinishTime.toTime();	
			c_UsualShift.insert(row_Shift);
		} 
		c_Employee.Usual_Shift.insert(c_UsualShift);
		info "-------------";
    }
  1.  // 
  2.      // select applicable staff 
  3.      l_ApplicableStaff = Staff[ID != 0]
  4.      for each c_Employee in l_ApplicableStaff 
  5.      { 
  6.          info c_Employee.Name; 
  7.          // 
  8.          // reset the stuff they already have in their subform "Usual Shift" 
  9.          c_Employee.Usual_Shift.clear()
  10.          // 
  11.          // great now let's build a ZohoCreator subform 
  12.          c_UsualShift = Collection()
  13.          for each v_WorkDay in m_ShiftBuildUp.keys() 
  14.          { 
  15.              info v_WorkDay; 
  16.              // 
  17.              // format the opening time and closing time 
  18.              v_StartTime = zoho.currenttime.toString("yyyy-MM-dd ") + m_ShiftBuildUp.get(v_WorkDay).get("open").leftpad(5).replaceAll(" ", "0") + ":00"
  19.              v_FinishTime = zoho.currenttime.toString("yyyy-MM-dd ") + m_ShiftBuildUp.get(v_WorkDay).get("close").leftpad(5).replaceAll(" ", "0") + ":00"
  20.              // 
  21.              row_Shift = Staff.Usual_Shift()
  22.              row_Shift.Day = v_WorkDay; 
  23.              row_Shift.Start_Time = v_StartTime.toTime()
  24.              row_Shift.End_Time = v_FinishTime.toTime()
  25.              c_UsualShift.insert(row_Shift)
  26.          } 
  27.          c_Employee.Usual_Shift.insert(c_UsualShift)
  28.          info "-------------"; 
  29.      } 
Yields something like:
ZohoCRM: Get Organization Business Hours using Deluge/API


Error(s) Encountered
  • Value is empty and '1234567000001234567' function cannot be applied:   Possibly due to me trying to create and declare the subform before having specified any record to insert it into.
  • Expecting ZC_SUBFORM_109 expression found COLLECTION expression:   I may have tried to make a subform equal the collection rather than inserting the collection into the subform using insert().
  • Invalid update task found corresponding properties:   Trying to update a time field with a string is a no go. Set it to an atom time or nice SQL date/time (eg. "yyyy-MM-dd HH:mm:ss") and then apply the function .toTime()

Source(s)
Category: Zoho CRM :: Article: 373

Credit where Credit is Due:


Feel free to copy, redistribute and share this information. All that we ask is that you attribute credit and possibly even a link back to this website as it really helps in our search engine rankings.

Disclaimer: Please note that the information provided on this website is intended for informational purposes only and does not represent a warranty. The opinions expressed are those of the author only. We recommend testing any solutions in a development environment before implementing them in production. The articles are based on our good faith efforts and were current at the time of writing, reflecting our practical experience in a commercial setting.

Thank you for visiting and, as always, we hope this website was of some use to you!

Kind Regards,

Joel Lipman
www.joellipman.com