Add custom button inside of table by script

I need add a custom button in a purposes table, in maintenance visit.

Tried:

frappe.ui.form.on("Maintenance Visit", "refresh", function(frm){
	$.each (frm.doc.purposes, function(i, d){
		frm.doc.purposes[i].add_custom_button("Orçamento"), function(){}
	});
});

Some help?

Add custom field in Maintenance Visit Purpose with field type Button

image

you can trigger it as follow,

write Custom script for form - Maintenance Visit

frappe.ui.form.on("Maintenance Visit Purpose", "orçamento", function(frm, cdt, cdn){
	//Script
})

But i don’t wanna add a custom field, i wanna add the button by script.
It’s possible do this in a table?

What is your use case?

Why ?

If some condition, add button.

add button through Customize Form/Custom Field. and hide/show it on condition,

e.g.

cur_frm.fields_dict['table_name'].grid.toggle_display("table_fieldname", condition);

I’ll try that, thanks!

I can not use if in this condition?
Can you give me an example?

condition means here which returns true/false or 0/1.

e.g.

cur_frm.fields_dict['table_name'].grid.toggle_display("table_fieldname", frm.doc.__islocal);

But i need to use a if, cause is a select box… Depending of the string, the button will appear/hide

So what is your if condition or syntax? Paste here

if (frm.doc.custom_field == “Interno”)

then try this,

cur_frm.fields_dict['table_name'].grid.toggle_display("table_fieldname", frm.doc.custom_field == “Interno”);