Update field according to other field's value

Hi,
I would like to write a script that updates a field value according to other field’s value in the same table and row.
In the Timesheet doctype, there is a child table called Timesheet Detail. this child table has few fields. one of the fields is a checkbox type field, called “Bill”. I need this field to have a “true” value, in case the activity_type field equals a certain value (“Billable”).
Can anyone assist with the script?

Thanks!

Hello;
This is possible using custom code as following:

frappe.ui.form.on('Timesheet Details', {
        activity_type: function(frm, cdt, cdn) {
                var item = locals[cdt][cdn];
                if (item['activity_type'] == 'Billable') {
                        item['bill'] = 1;
                }
        },
});

This can be added as custom script or can be added in separated custom application but in this case there are steps that you need to proceed in it, please check this link as reference for you:

Regards
Bilal

Thanks Bilal, however, this does not seem to work, the field is not updated. Any ideas?

Hello @shaiga

Please just add refresh_field(time_logs); in the below code:

  frappe.ui.form.on('Timesheet Details', {
            activity_type: function(frm, cdt, cdn) {
                    var item = locals[cdt][cdn];
                    if (item['activity_type'] == 'Billable') {
                            item['bill'] = 1;
                            refresh_field(time_logs);
                    }
            },
    });

And let me know if you get any error in the browser development tools, I need to check if any problem is happened. Do you know how to check the browser error?

Regards
Bilal

please let me know how to check the browser error?

Hi @tusar75,

Please click F12 then go to the Console tab to check your error.

Thanks.