fetch customer/supplier given a contact in communication
diff --git a/erpnext/support/doctype/communication/communication.js b/erpnext/support/doctype/communication/communication.js
index 36e5c90..9b7b896 100644
--- a/erpnext/support/doctype/communication/communication.js
+++ b/erpnext/support/doctype/communication/communication.js
@@ -91,4 +91,23 @@
 		
 		var record_list_view = new RecordListView(doctype, wrapper, ListView);
 	});
+}
+
+
+cur_frm.cscript.contact = function(doc, dt, dn) {
+	if (doc.contact) {
+		wn.call({
+			method: 'support.doctype.communication.communication.get_customer_supplier',
+			args: {
+				contact: doc.contact
+			},
+			callback: function(r, rt) {
+				if (!r.exc && r.message) {
+					doc = locals[doc.doctype][doc.name];
+					doc[r.message['fieldname']] = r.message['value'];
+					refresh_field(r.message['fieldname']);
+				}
+			},
+		});
+	}
 }
\ No newline at end of file
diff --git a/erpnext/support/doctype/communication/communication.py b/erpnext/support/doctype/communication/communication.py
index c99422d..8382eb7 100644
--- a/erpnext/support/doctype/communication/communication.py
+++ b/erpnext/support/doctype/communication/communication.py
@@ -17,6 +17,26 @@
 import webnotes
 from webnotes.model.doc import make_autoname
 
+@webnotes.whitelist()
+def get_customer_supplier(args=None):
+	"""
+		Get Customer/Supplier, given a contact, if a unique match exists
+	"""
+	import webnotes
+	if not args: args = webnotes.form_dict
+	if not args.get('contact'):
+		raise Exception, "Please specify a contact to fetch Customer/Supplier"
+	result = webnotes.conn.sql("""\
+		select customer, supplier
+		from `tabContact`
+		where name = %s""", args.get('contact'), as_dict=1)
+	if result and len(result)==1 and (result[0]['customer'] or result[0]['supplier']):
+		return {
+			'fieldname': result[0]['customer'] and 'customer' or 'supplier',
+			'value': result[0]['customer'] or result[0]['supplier']
+		}
+	return {}
+
 class DocType():
 	def __init__(self, doc, doclist=[]):
 		self.doc = doc