Add Custom Button in child table

Hello there…

how to add custom button into child table row…??

i try set button into value but it’s doesnt work

frappe.ui.form.on("Organisasi",{
"organitation_name": function(frm, cdt, cdn) {

	var d = locals[cdt][cdn];
    var comunity_name = frm.doc.organitation_name[2].organitation_name.split('-')[0]
    var city = frm.doc.organitation_name[2].organitation_name.split('-')[1].replace(/\s/g, '');

    var post_data = {'comunity_name': comunity_name, 'city': city};
    var json_data = JSON.stringify( post_data );
    $.ajax({
        type: 'POST',
        url: '/get_komunitas1',
        data: json_data,
        success: function(datai){
            frappe.model.set_value(cdt, cdn, "status", "not connect");
    		frappe.model.set_value(cdt, cdn, "comunity_location", datai.message['city']);
    		if(datai.message['kode_komunitas'] == 'KUM'){
	        	frappe.model.set_value(cdt, cdn, "comunity_type", "Komunitas");
	        }

	        frappe.model.set_value(cdt, cdn, "actions", set_button(frm));
	        frm.refresh_field("actions");
	    }
	});
}

});

var set_button = function(frm){
return cur_frm.add_custom_button(“connect”, function(){

	var post_data =
    {
        "kode": v['kode'],
        "comunity_name": v['comunity_name']
    }

	$.ajax({
        type: 'POST',
        url: '/remove_member',
        data: post_data,
        success: function(datai){
            console.log(datai)
        },
        error: function(datai){
            console.log('error log', datai)
            return false;
        }
    });
});

}

it should be show button, but still show object
01

Hi there,

Did you solve the problem, I am having the same question.

Thank you,

Edit your child doctype to add the button.

Expand the row of your button and set :

Then in custom script or the JS file, add JS code like this

frappe.ui.form.on("Test Child",{
	set_full_name: function(frm, cdt, cdn){
		var d = locals[cdt][cdn]
		frappe.msgprint(d.first_name + " " + d.last_name)
	}
})

I saved this code in the JS file of the parent doctype which in my case was another doctype was Author. If you are using Custom Script then setting the parent doctype in the Doctype field of the custom script should be good enough.

set_full_name in my case was the button field name. You can have your work done via JS or you can call a Python function to do the heavylifting

Execution of the code on button click:

7 Likes

Thank You very much