This should be work:
/**
*@NApiVersion 2.x
*@NScriptType ClientScript
*/
define([],
function() {
function fieldChanged(context) {
var fieldName = context.fieldId;
//return if not one of these fields
if (fieldName !== 'custrecord_am_ehir_emp_prem_percent' &&
fieldName !== 'custrecord_am_ehir_dep_prem_percent' &&
fieldName !== 'custrecord_am_ehir_total_month_prem') {
return false;
} else {
//get premium and percent values
var totalPremium = context.currentRecord.getValue({
fieldId: 'custrecord_am_ehir_total_month_prem'
});
var employeeOnlyPremium = context.currentRecord.getValue({
fieldId: 'custrecord_am_ehir_emp_only_prem'
});
var employeePercent = context.currentRecord.getValue({
fieldId: 'custrecord_am_ehir_emp_prem_percent'
});
var dependentPercent = context.currentRecord.getValue({
fieldId: 'custrecord_am_ehir_dep_prem_percent'
});
var employeePremium = totalPremium * employeePercent;
var dependentPremium = (totalPremium - employeeOnlyPremium) * dependentPercent;
var companyPremium = totalPremium - employeePremium - dependentPremium;
//set field values
context.currentRecord.setValue({
fieldId: 'custrecord_am_ehir_emp_month_prem',
value: employeePremium
});
context.currentRecord.setValue({
fieldId: 'custrecord_am_ehir_dep_month_prem',
value: dependentPremium
});
context.currentRecord.setValue({
fieldId: 'custrecord_am_ehir_co_month_prem',
value: companyPremium
});
}
}
return { fieldChanged: fieldChanged };
}
);