ERPNext Foundation ERPNext Cloud User Manual Blog Discuss Frappé* Donate

Client side doc creation (posting_date)


#1

I am trying to create a new Sales Invoice doc via client side scripting, but I am struggling quite a bit. Most immediately, I’m having trouble setting either the posting_date or the due_date programmatically. My code is below:

frappe.ui.form.on('Program Enrollment', {
    refresh: function(frm) {
	    frm.add_custom_button(__('Generate invoice'), function() {
		console.log(frm.doc.enrollment_date);
		console.log(frappe.datetime.get_today());
		frappe.run_serially([
		    () => frappe.route_options = {
			"posting_date": frm.doc.enrollment_date,
			"due_date": frappe.datetime.get_today(),
			"company": "Kula Culture Management Training, Pvt. Ltd."
		    },
		    () => frappe.new_doc("Sales Invoice")
		]);
	    });
    }
});

Company sets fine, and both of the console.log calls return results that I would expect to work (similar to “2019-05-24”). Any ideas?