Button with custom link in form

Hi guys,
I’m trying to add button that will open custom link in new window.
Every part has supplier’s part number. Eg. component A from Mouser has PN ABCD123, and “search query” for Mouser is “https://eu.mouser.com/Search/Refine?Keyword={TEXT}”. So I want to create the button that will open “https://eu.mouser.com/Search/Refine?Keyword=ABCD123” in new window.
Search query is in Supplier form(Supplier.search_link) while part number is in Item Supplier, field supplier_part_no.
Button should be in table witn supplier part numbers(one pn, one button).

How can I do that?

I have tried something similar. In the end I opted for the HTML type field then I render the button using javascript. The link was also added using javascript too, with the required parameters from the current document.

Thanks for help! But how to set up that? Where to paste JS code?

Hey, there are 2 places where you need to update.

under you /public/js
put your template file. This would be with .html extension. The template should be written in Jinja.

Then in /public/build.json, specify where you want to compile the template into.
“js/yourtemplate.js”: ["public/js/yourtemplate.html]

Then in you hook file, I use app_include_js settings to load that js.

The javascript to load the template and to specify the actions can then be written via custom script.

There are some examples in the ERPNext repo if you look around some of the more advanced doctypes. Customer doctype is a good example, where the address is actually rendered like this.

Note, it’s been months since I had to do this, there might be better ways from the community perhaps.

Thanks, but button should be in “expanded” row view in table with supplier part numbers. Why I need custom doctype for that?

It’s just custom app, not necessarily new doctype.