Thursday 14 May 2015

Interaction with refresh comment and custom field

frappe.ui.form.on("Sales Order", "refresh", function(frm, doctype, name) {
cur_frm.add_custom_button(__('Add Interaction'), function() {
var d = frappe.prompt([
    {'fieldname': 'responce_reson', 'fieldtype': 'Data', 'label': 'Responce Reson', 'reqd': 1},
    {'fieldname': 'next_date', 'fieldtype': 'Date', 'label': 'Next Contact Date', 'reqd': 1},
    {'fieldname': 'comment', 'fieldtype': 'Text', 'label': 'Comment', 'reqd': 1}
],
function(values){
    var c = d.get_values()
    var cmnt = c.comment
    var me = frm.doc
    return frappe.call({
            method: "frappe.desk.form.utils.add_comment",
            args: {
                doc:{
                    doctype: "Comment",
                    comment_type: "Comment",
                    comment_doctype: frm.doc.doctype,
                    comment_docname: frm.doc.name,
                    comment: cmnt,
                                        responce_reson: c.responce_reson,
                                        next_date: c.next_date,
                    comment_by: user
                }
            },
            callback: function(r) {
            if (cur_frm) {
                        if (cur_frm.docname && (frappe.last_edited_communication[cur_frm.doctype] || {})[cur_frm.docname]) {
                            delete frappe.last_edited_communication[cur_frm.doctype][cur_frm.docname];
                        }
                        // clear input
                        cur_frm.comments.input.val("");
                        cur_frm.reload_doc();
                    }
            }
        });
},
'Add Interaction',
'Submit'
)
}, "icon-exclamation", "btn-default");

                        frm.comments.refresh();

});

No comments:

Post a Comment