How to redirect to new doc in .js file?

i need to open a new Purchase invoice when click on the button on the form in Project.

I see how the task opens on a button click as below:

edit_task: function(frm, doctype, name) {
		var doc = frappe.get_doc(doctype, name);
		if(doc.task_id) {
			frappe.set_route("Form", "Task", doc.task_id);
		} else {
			msgprint(__("Save the document first."));

But in my case i have no id. ie i want to open a new doc. how to code this need?

Try, new_doc("Doctype Name")

1 Like

Thank you @makarand_b

frappe.new_doc("Purchase Invoice")

it worked !!!