def execute_action(doctype, name, action, **kwargs):
 doc = frappe.get_doc(doctype, name)
 doc.unlock()
 try:
  getattr(doc, action)(**kwargs)
 except Exception:
  frappe.db.rollback()
  if frappe.local.message_log:
   msg = json.loads(frappe.local.message_log[(-1)]).get(u'message')
  else:
   msg = ((u'<pre><code>' + frappe.get_traceback()) + u'</pre></code>')
  doc.add_comment(u'Comment', ((_(u'Action Failed') + u'<br><br>') + msg))
  doc.notify_update()

def execute_action ( doctype , name , action , ** kwargs ) : doc = frappe . get_doc ( doctype , name ) doc . unlock ( ) try : getattr ( doc , action ) ( ** kwargs ) except Exception : frappe . db . rollback ( ) if frappe . local . message_log : msg = json . loads ( frappe . local . message_log [ ( - 1 ) ] ) . get ( u'message' ) else : msg = ( ( u'<pre><code>' + frappe . get_traceback ( ) ) + u'</pre></code>' ) doc . add_comment ( u'Comment' , ( ( _ ( u'Action Failed' ) + u'<br><br>' ) + msg ) ) doc . notify_update ( )
execute an action on a document .