Wednesday, July 6, 2016

White Listed Method

To make REST call or want to access method from js you need to make those methods as whitelisted.
@frappe.whitelist() is Decorator for whitelisting a function and making it accessible via HTTP.Standard request will be `/api/method/[]` :param allow_guest: Allow non logged-in user to access this method. Use a @frappe.whitelist() def myfunc(param1, param2): pass{ method: "erpnext.crm.doctype.opportunity.opportunity.get_item_details", args: {"item_code":d.item_code}, callback: function(r, rt) { if(r.message) { alert(r.message.item_name) } })Python@frappe.whitelist() def get_item_details(item_code): item = frappe.db.sql("""select item_name, stock_uom, image, description, item_group, brand from `tabItem` where name = %s""", item_code, as_dict=1) return item.item_name

1 comment: