How to appear send sms in menu like this?


This is in the sales invoice I want like it i appear the button in the journal entry.

Please apply it and add your logic according to the scenario.

frappe.ui.form.on('Journal Entry', {
	refresh: function(frm) {
	    if (!frm.is_new()) {
    	    frm.page.add_menu_item(__('Send SMS'), function() {
    	        // add your logic
    	        frappe.msgprint("SMS Sent");
    	    });
	    }
	}
});

@manal_erpnext Kindly use the whitelisted method for the send_sms function, and include a mention of @NCP above.

1 Like

how could i get the code of it in sales invoice to write the same logic


i mean like this?

Please check the logic:

frappe.ui.form.on('Journal Entry', {
    refresh: function(frm) {
        if (frm.doc.docstatus === 1) {
            frm.page.add_menu_item(__('Send SMS'), function() {
                send_sms(frm);
            });
        }
    }
});

function send_sms(frm) {
    var sms_manager = new erpnext.SMSManager(frm.doc);
}

erpnext.SMSManager = function SMSManager(doc) {
    var me = this;

    this.setup = function () {
        var default_msg = {
            "Journal Entry": "Journal Entry " + doc.name + " has been recorded."
        };

        if (doc.doctype === "Journal Entry") {
            this.show("", "", "", doc.contact_no || doc.party_mobile, default_msg[doc.doctype]);
        }
    };

    this.get_contact_number = function (contact, ref_doctype, ref_name) {
        frappe.call({
            method: "frappe.core.doctype.sms_settings.sms_settings.get_contact_number",
            args: {
                contact_name: contact,
                ref_doctype: ref_doctype,
                ref_name: ref_name,
            },
            callback: function (r) {
                if (r.exc) {
                    frappe.msgprint(r.exc);
                    return;
                }
                me.number = r.message;
                me.show_dialog();
            },
        });
    };

    this.show = function (contact, ref_doctype, ref_name, mobile_nos, message) {
        this.message = message;
        if (mobile_nos) {
            me.number = mobile_nos;
            me.show_dialog();
        } else if (contact) {
            this.get_contact_number(contact, ref_doctype, ref_name);
        } else {
            me.show_dialog();
        }
    };

    this.show_dialog = function () {
        if (!me.dialog) me.make_dialog();
        me.dialog.set_values({
            message: me.message,
            number: me.number,
        });
        me.dialog.show();
    };

    this.make_dialog = function () {
        var d = new frappe.ui.Dialog({
            title: "Send SMS",
            width: 400,
            fields: [
                { fieldname: "number", fieldtype: "Data", label: "Mobile Number", reqd: 1 },
                { fieldname: "message", fieldtype: "Text", label: "Message", reqd: 1 },
                { fieldname: "send", fieldtype: "Button", label: "Send" },
            ],
        });
        d.fields_dict.send.input.onclick = function () {
            var btn = d.fields_dict.send.input;
            var v = me.dialog.get_values();
            if (v) {
                $(btn).set_working();
                frappe.call({
                    method: "frappe.core.doctype.sms_settings.sms_settings.send_sms",
                    args: {
                        receiver_list: [v.number],
                        msg: v.message,
                    },
                    callback: function (r) {
                        $(btn).done_working();
                        if (r.exc) {
                            frappe.msgprint(r.exc);
                            return;
                        }
                        me.dialog.hide();
                    },
                });
            }
        };
        this.dialog = d;
    };
    
    this.setup();
};
1 Like