79471582

Date: 2025-02-27 04:18:11
Score: 0.5
Natty:
Report link

This should be work:

  1. Don't load the current record module: Avoid loading unnecessary modules to improve performance.
  2. Use the context to retrieve the fieldId ( see https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_4410692508.html )
  3. Use the right methods parameters for setters and getters ( see https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_4637582256.html, https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_4637577499.html )

/**
 *@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 };
    }
);

Reasons:
  • Probably link only (1):
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: cesar parra