Wednesday, July 20, 2016

How to create a simple HTML table using Custom script in erpnext ?

  • Add a custom HTML field in your target doctype (doctype that will show the table)
  • Add the code below as a custom script for the target doctype
frappe.ui.form.on('Target Doctype', 'refresh', function(frm, cdt, cdn){
   frappe.call({
     'method': 'frappe.client.get_list',
     'args': {
       'doctype': 'Source DocType',
       'columns': ['*']
       'filters': [['Source DocType', 'link_reference', '=', frm.doc.name]]
     },
     'callback': function(res){
         var template = "<table><tbody>{% for (var row in rows) { %}<tr>{% for (var col in rows[row]) { %}<td>rows[row][col]</td>{% } %}</tr>{% } %}</tbody></table>",
        frm.set_df_property('html_fieldname', 'options', frappe.render(template, {rows: res.message});
        frm.refresh_field('html_fieldname');
     }
   })
});

3 comments:

  1. Thanks for your effort brother

    You saved me a lot of time with this post.

    Barak Allah Feek

    ReplyDelete
  2. hello Hafees, what is the Source Doctype ?

    ReplyDelete