Fixed issue: agents weren't looked up in settings
diff --git a/erpnext/crm/doctype/appointment/appointment.py b/erpnext/crm/doctype/appointment/appointment.py
index 4dea04b..3a588fb 100644
--- a/erpnext/crm/doctype/appointment/appointment.py
+++ b/erpnext/crm/doctype/appointment/appointment.py
@@ -3,37 +3,15 @@
 # For license information, please see license.txt
 
 from __future__ import unicode_literals
+
 from collections import Counter
 from datetime import timedelta
+
 import frappe
 from frappe.model.document import Document
 from frappe.desk.form.assign_to import add as add_assignemnt
 
 
-def _get_agents_sorted_by_asc_workload():
-	appointments = frappe.db.get_list('Appointment', fields='*')
-	# Handle case where no appointments are created
-	appointment_counter = Counter()
-	if not appointments:
-		return frappe.get_doc('Appointment Booking Settings').agent_list
-	for appointment in appointments:
-		if appointment._assign == '[]' or not appointment._assign:
-			continue
-		appointment_counter[appointment._assign] += 1
-	sorted_agent_list = appointment_counter.most_common()
-	sorted_agent_list.reverse()
-	return sorted_agent_list
-
-def _check_agent_availability(agent_email,scheduled_time):
-	appointemnts_at_scheduled_time = frappe.get_list('Appointment', filters={'scheduled_time':scheduled_time})
-	for appointment in appointemnts_at_scheduled_time:
-		if appointment._assign == agent_email:
-			return False
-	return True
-
-def _get_employee_from_user(user):
-	return frappe.get_list('Employee', fields='*',filters={'user_id':user})
-
 class Appointment(Document):
 	def validate(self):
 		number_of_appointments_in_same_slot = frappe.db.count('Appointment',filters={'scheduled_time':self.scheduled_time})
@@ -74,4 +52,49 @@
 						reference_docname=employee[0].name))
 					print(calendar_event)
 					calendar_event.save()
-				break
\ No newline at end of file
+				break
+
+
+def _get_agents_sorted_by_asc_workload():
+	appointments = frappe.db.get_list('Appointment', fields='*')
+	agent_list = _get_agent_list_as_strings()
+	
+	if not appointments:
+		return agent_list
+	
+	appointment_counter = Counter(agent_list)
+	
+	for appointment in appointments:
+		assigned_to = frappe.parse_json(appointment._assign)
+		print(assigned_to)
+		if appointment._assign == '[]' or not appointment._assign:
+			continue
+		if assigned_to[0] in agent_list:
+			appointment_counter[assigned_to[0]] += 1
+	
+	sorted_agent_list = appointment_counter.most_common()
+	sorted_agent_list.reverse()
+	
+	return sorted_agent_list
+
+
+def _get_agent_list_as_strings():
+	agent_list_as_strings = []
+	agent_list = frappe.get_doc('Appointment Booking Settings').agent_list
+	
+	for agent in agent_list:
+		agent_list_as_strings.append(agent.user)
+	
+	return agent_list_as_strings
+
+
+def _check_agent_availability(agent_email,scheduled_time):
+	appointemnts_at_scheduled_time = frappe.get_list('Appointment', filters={'scheduled_time':scheduled_time})
+	for appointment in appointemnts_at_scheduled_time:
+		if appointment._assign == agent_email:
+			return False
+	return True
+
+
+def _get_employee_from_user(user):
+	return frappe.get_list('Employee', fields='*',filters={'user_id':user})
\ No newline at end of file