Redirecting to new doc

I have an script that when i click on the button this does:
frappe.new_doc(“Payment Entry”)
But i need open this current Payment Entry, what’s the method to do this?

look up set_route:

What’s the “List”, “Leave Allocation”, “leave_type” ?
Module, doctype, ??

The Script:

JS:

frappe.ui.form.on("Titulos", "refresh", function(frm) {
	if(frm.doc.workflow_state=="Liberado"){
		frm.add_custom_button(__("Rascunho"), function() {
        		// When this button is clicked, do this
			frappe.call({
			method: "erpnext.accounts.utils.make_payment_entry",
			args:{},
            		callback: function(r)
            		{console.log(r)}
			});
		});
	}
});

PY:

@frappe.whitelist()
    def make_payment_entry():
    frappe.new_doc("Payment Entry")
    payment_entry.party_type("Supplier")
    return ()

I did test with this script:

frappe.set_route("List", "Leave Allocation",
			{"leave_type": frm.doc.name});

and that worked!
I’ll try reply on my case now, thank you! @Ben_Cornwell_Mott

I don’t know what i have to put in there ???
Im redirecting to a new form, so has some differences about List…

frappe.set_route("Form", "Payment Entry",
			{"???": frm.doc.name});

Can you give me an example using my case please? @Ben_Cornwell_Mott
It’s more easy to understand…

There are dozens of examples on github showing exactly how to do it. Try looking through the core code instead of asking for help the second you run into trouble.

These examples all call this function:

So work through that code to see what you need to provide to it.

1 Like

Thank you so much! @Ben_Cornwell_Mott
Trying now, let me ask you something… How can you find this things so fast?
How can i find what i need in the github of erpnext like you do?

You just use the github search tool.

See… But how you knew that i need set_route function?

I knew from trying to do the same thing as you. But when I needed to figure it out the first time, I found a document that had that functionality then looked through the javascript code for that document to understand how it worked.

See… i tried:
frappe.set_route("Form", "Payment Entry");

Error:
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 282, in _raise_exception
raise raise_exception(encode(msg))
DoesNotExistError: Payment Entry Payment Entry not found

It’s missing something?

You are missing the name of the document you are trying to open. Try this:

document = frappe.new_doc(“Payment Entry”);
frappe.set_route(“Form”, “Payment Entry”, document .name);

This is not a javascript?
Im trying in javascript…

i will receive frappe.new_doc two times?
I’m already doing this on python

Tried:

frappe.ui.form.on("Titulos", "refresh", function(frm) {
	if(frm.doc.workflow_state=="Liberado"){
		frm.add_custom_button(__("Rascunho"), function() {
        		// When this button is clicked, do this
			frappe.call({
				method: "erpnext.accounts.utils.make_payment_entry",
				args:{},
            			callback: function(r)
            			{console.log(r)}
			});
		document = frappe.new_doc("Payment Entry");
		frappe.set_route("Form", "Payment Entry", document.name);
		});
	}
});

Same error :confused:

I’m not sure why you are using python at all for this, but…
Try this:
JS:

frappe.ui.form.on("Titulos", "refresh", function(frm) {
	if(frm.doc.workflow_state=="Liberado"){
		frm.add_custom_button(__("Rascunho"), function() {
        		// When this button is clicked, do this
			frappe.call({
			method: "erpnext.accounts.utils.make_payment_entry",
			args:{},
            	callback: function(r)
            	{
            	      frappe.set_route("Form", "Payment Entry", r.message.name)
            	}
			});
		});
	}
});

PY:

@frappe.whitelist()
def make_payment_entry():
    payment_entry = frappe.new_doc("Payment Entry")
    payment_entry.party_type = "Supplier"
    payment_entry.save()
    return payment_entry.name

What is the error you are getting?

Hum… I understand, this will open document using the name of the new doc.
But Im already doing frappe.new_doc in python script, so… I have to receive the variable of python script

VM19876:10 Uncaught TypeError: Cannot read property ‘name’ of undefined
at Object.callback (eval at setup (form.min.js:2555), :10:57)
at Object.callback [as success_callback] (desk.min.js:1201)
at _ (desk.min.js:1225)
at Object. (desk.min.js:1321)
at i (jquery.min.js:2)
at Object.fireWith [as resolveWith] (jquery.min.js:2)
at z (jquery.min.js:4)
at XMLHttpRequest. (jquery.min.js:4)

Please change frappe.set_route("Form", "Payment Entry", r.message.name) to console.log(r.message); and report back the console output (as a screenshot).