ERPNext Conference 2019* ERPNext.com Blog

Link to another Doctype With Button Field


#1

I was wondering how to link from one Doctype ( via an “onClick” on a button field called “My Link Button”) to another Doctype in different module? Say to Selling/Customer/Form?

Also is there an easy way to add a basic javascript script to go back one page on a button field??
Something like:
function goBack() {
window.history.back();
}

Any help in getting this code to work would be really appreciated.
Thanks.


[SOLVED] How to open doctype B after saving doctype A?
#2

add href="#Form/Customer/CustomerName" to your button

or

frappe.set_route("Form", "Customer", "CustomerName")

#3

Thanks for the reply @rmehta.
Where would I add frappe.set_route(“Form”, “Customer”, “CustomerName”) ?
In the Doctype .js file the .py file or somewhere like the “depends on” field of the button ?
An example of how it should be included would be really appreiciated.
Thanks


#4

Custom Script

frappe.ui.form.on("Customer", "my_button", function(frm) {
  frappe.set_route("Form", "Customer", "CustomerName")
});

#5

Excellent. Thanks for the help @rmehta . :smile:


#6

@rmehta The back button of the browser doesn’t work if you navigate to a doctype using the set_route method. The back button creates a new entry. Any solution?


#7

Is it possible to map multiple field values at a time through the frappe.set_route function ?

ex: frappe.set_route(“Form/Import Permission Received Items/New Import Permission Received Items”, {“permission_number”: frm.doc.name} , and **{“received_item”: item_name} ** )

i need to update a doc-type against the permission number and item name .

screenshots of my doctyps:


regards.


#8

Yes, that’s possible:

frappe.set_route("Form", "Import Permission Received Items", {
    "permission_number": frm.doc.name, 
    "received_item": frm.doc.item_name,
});

#9

how to add back button functionality in the existing system
if you know this functionality please let me know

Thanks