Call frappe.get_last_doc(doctype) with give permission error

I am trying to use frappe.get_last_doc(doctype)
to get last created doc via custom script{
    args: {doctype:"Sales Invoice"}, 
    callback: function(r) { 


Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 61, in application
    response = frappe.handler.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 21, in handle
    data = execute_cmd(cmd)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 54, in execute_cmd
  File "/home/frappe/frappe-bench/apps/frappe/frappe/", line 76, in is_whitelisted
    raise frappe.PermissionError('Not Allowed, {0}'.format(method))
PermissionError: Not Allowed, <function get_last_doc at 0x7f69c9af16e0>

get_last_doc method is not whitelisted. You cannot call it from the client side.
You should use frappe.db.get_list in combination with frappe.db.get_doc to get what you want.