Newsletter with employees name

Hi @Khadija,

we had a similar requirement on newsletters, where they should be personalised (customer name, …). Have have solved this by extending the newsletter function with a custom button “Send with dynamic content” and added some server side code which replaces predefined strings in the newsletter body. You can find the source here:

The custom script looks like this:

frappe.ui.form.on("Newsletter", {
  refresh: function(frm) {
	if ((!frm.doc.__islocal) && (frm.doc.email_sent == 0)) {
		frm.add_custom_button(__("Dynamisch senden"), function() {
			send_dynamic(frm);
		});
		frm.add_custom_button(__("Vorlage einlesen"), function() {
			load_template(frm);
		});
	}
  }
});

function send_dynamic(frm) {
	frappe.call({
		method: 'erpnextswiss.erpnextswiss.dynamic_newsletter.enqueue_send_dynamic_newsletter',
		args: {
		newsletter: frm.doc.name
		},
		callback: function(r) {
			frappe.msgprint(  
				__("The newsletter has been added to the sending queue. It will be sent in the next few minutes."),
				__("Newsletter sending") );
		}
	});
}

function load_template(frm) {
  frappe.prompt([
	  {'fieldname': 'template', 'fieldtype': 'Link', 'label': 'Vorlage', 'options': 'Terms and Conditions', 'reqd': 1}  
	],
	function(values){
	  frappe.call({
		"method": "frappe.client.get",
		"args": {
			"doctype": "Terms and Conditions",
			"name": values.template
		},
		"callback": function(response) {
			var terms = response.message;
			if (terms) {
				cur_frm.set_value('message', terms.terms);
			} 
		}
	});
	},
	'Vorlage auswählen',
	'OK'
  )
}

Hope this helps. (Maybe this also helps How to add custom fields to Newsletter using jinja?)

2 Likes