Try ERPNext Buy Support Partners Foundation

Custom Script Not Working?

Something strange happening, I had a similar script which is working but the below script that I placed in Employee doctype isnt working.

frappe.ui.form.on('Employee External Work History', {
    refresh(frm) {
        set_salary(frm);
    },
    validate: function(frm) {
        set_salary(frm);
    },
    basic_salary: function(frm) {
        set_salary(frm);
    },
    fixed_allowance: function(frm) {
        set_salary(frm);
    },
    last_drawn_commission_incentive: function(frm) {
        set_salary(frm);
    }
});

var set_salary = function(frm, cdt, cdn) {
    var salary = 0.0;
    if(frm.doc.external_work_history) {
        $.each(frm.doc.external_work_history, function(i, row) {
            row.salary = row.basic_salary + row.fixed_allowance + row.last_drawn_commission_incentive;
        });
        frappe.model.set_value(cdt, cdn, 'row.salary', row.salary);
        return;
    }
};

Below is the Customize Form of Employee External Work History

Hi
To set value for field in child table use following:
frappe.model.set_value(row.cdt, row.cdn, ‘row.field’, value);
refesh_field('child_table_name_in_form)

To set value for field in form use following:
frm.set_value(‘field_name’, value)
refresh_field(‘field_name’)

try to set value from inside the loop
if(frm.doc.external_work_history) {
$.each(frm.doc.external_work_history, function(i, row) {
var salary = row.basic_salary + row.fixed_allowance + row.last_drawn_commission_incentive;
frappe.model.set_value(cdt, cdn, ‘row.salary’, salary );
});