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/[path.to.method]` :param allow_guest: Allow non logged-in user to access this method. Use a @frappe.whitelist() def myfunc(param1, param2): pass ExampleJavascriptfrappe.call({ 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

4 comments:

  1. Thanks this has been an eye opener

    ReplyDelete
  2. Tried this from erpnext virtualbox setup in development mode. getting error as 'module' has not attribute 'method_name'

    ReplyDelete