Log Call button - for community use

Built a feature today that may be useful to many other users so I wanted to share.

These scripts add a “Log Call” button in Lead and Opportunity, prompting the user for a next contact date (which updates the form) and creates a communication with the content from the prompt.

The auto-populate fields are Select instead of read-only, as the read only fields would not populate with a default.It also makes the assumption that the next contact by user is the same user that last saved the form. But, these are easy to change in the scripts. Enjoy!

frappe.ui.form.on("Lead", "refresh", function(frm) {
    frm.add_custom_button(__("Log Call"), function(foo) {
      var communication = frappe.prompt([
          {label: "Contact", fieldtype: "Select", options: frm.doc.lead_name,
          default:frm.doc.lead_name},
          {fieldtype: "Column Break"},
          {label: "Phone", fieldname: "phone_no", fieldtype: "Select",
          options: [frm.doc.phone, frm.doc.mobile_no], default: frm.doc.phone},
          {fieldtype: "Section Break"},
          {label: "Sent or Received", fieldname: "sent_or_received",
          fieldtype: "Select", options: ["Sent", "Received"], default: "Sent"},
          {fieldtype: "Column Break"},
          {label: "Next Contact Date", fieldtype: "Date", reqd: "1"},
          {fieldtype: "Section Break"},
          {label: "Subject", fieldtype: "Data", default: "Call " + (new Date())},
          {fieldtype: "Section Break"},
          {label: "Notes", fieldname: "content", fieldtype: "Small Text", reqd: "1"},
        ],
        function(data){
          data.doctype = "Communication";
          data.reference_doctype = frm.doc.doctype;
          data.reference_name = frm.doc.name;
          frm.doc.contact_date = data.next_contact_date;
          frm.doc.contact_by = frm.doc.modified_by;
          frm.save();
          frappe.call({
            method: "frappe.client.insert",
            args: {
              "doc": data
            }
          })
        })
    });
});

frappe.ui.form.on("Opportunity", "refresh", function(frm) {
    frm.add_custom_button(__("Log Call"), function(foo) {
      var communication = frappe.prompt([
          {label: "Contact", fieldtype: "Select", options: frm.doc.customer_name,
          default:frm.doc.customer_name},
          {fieldtype: "Column Break"},
          {label: "Phone", fieldname: "phone_no", fieldtype: "Select",
          options: [frm.doc.phone, frm.doc.contact_mobile], default: frm.doc.contact_mobile},
          {fieldtype: "Section Break"},
          {label: "Sent or Received", fieldname: "sent_or_received",
          fieldtype: "Select", options: ["Sent", "Received"], default: "Sent"},
          {fieldtype: "Column Break"},
          {label: "Next Contact Date", fieldtype: "Date", reqd: "1"},
          {fieldtype: "Section Break"},
          {label: "Subject", fieldtype: "Data", default: "Call " + (new Date())},
          {fieldtype: "Section Break"},
          {label: "Notes", fieldname: "content", fieldtype: "Small Text", reqd:"1"},
        ],
        function(data){
          data.doctype = "Communication";
          data.reference_doctype = frm.doc.doctype;
          data.reference_name = frm.doc.name;
          frm.doc.contact_date = data.next_contact_date;
          frm.doc.contact_by = frm.doc.modified_by;
          frm.save();
          frappe.call({
            method: "frappe.client.insert",
            args: {
              "doc": data
            }
          })
        })
    });
});
4 Likes

@alec_ruizramon1 nice. Will be good to add this in the product. Can you send a PR?

@rmehta sure, would love to! I had some issues with it raising Implicit Commit errors when trying to update the Comment feed, so also ended up creating a whitelisted function for updating the communication feed. Worked like a charm.

Where would you like the PR? Frappe or ERPNext?

Frappe? We can discuss over the PR!

1 Like

:+1: https://github.com/frappe/frappe/pull/1982

1 Like