How to add a custom button / field to the side bar of a doctype?

I basically want to add my own element into the side bar of a doctype, for example into “Purchase Order”. Do you know if and how that is possible? Thanks!

Hi @julez:

Use a client script for “Purchase Order” (and enable it!)

frappe.ui.form.on('Purchase Order', {
	refresh(frm) {
		const add_comment_button_html = `
            <div class="add-custom-button">
                <button class="btn btn-primary btn-sm btn-custom">
                    My button
                </button>
            </div><br>
        `;
        $(add_comment_button_html).insertAfter('.form-sidebar');
        
        $(document).on('click', '.btn-custom', function() {
          console.log("I'm here! Where are you?")
        })
	}
})

You will get this …

Hope this helps.

3 Likes

That is exactly what I was looking for. Thank you @avc