created a table on the table when we fill the morks from telugu to social ofter social then auto tot

pranayreddy
Giga Contributor
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

   //Type appropriate comment here, and begin script below
   if{newValue}

   
   
   {
   var t =parseInt( g_form.getValue('u_telugu'));
   var h = parseInt( g_form.getValue('u_hindhi'));
   var e = parseInt( g_form.getValue('u_english'));
   var m = parseInt( g_form.getValue('u_maths'));
   var sc =parseInt( g_form.getValue('u_science'));
   var s = parseInt( g_form.getValue('u_social'));
   var tl=parseInt (t+h+e+m+sc+s);
   g_form.setValue('u_total',tl);
   }
}
3 REPLIES 3

AniketC85155510
Kilo Patron

Hello @pranayreddy ,

there are a few issues in the provided onChange client script, so please give it a try to the below script once and let me know how that works for you.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

   // Sum all subject marks and set the total
   var t = parseInt(g_form.getValue('u_telugu')) || 0;
   var h = parseInt(g_form.getValue('u_hindhi')) || 0;
   var e = parseInt(g_form.getValue('u_english')) || 0;
   var m = parseInt(g_form.getValue('u_maths')) || 0;
   var sc = parseInt(g_form.getValue('u_science')) || 0;
   var s = parseInt(g_form.getValue('u_social')) || 0;

   var tl = t + h + e + m + sc + s;
   g_form.setValue('u_total', tl);
}

 

🔹 Please mark ✅ Correct if this solves your query, and 👍 Helpful if you found the response valuable.

 

Best regards,
Aniket Chavan
🏆 ServiceNow MVP 2025 | 🌟 ServiceNow Rising Star 2024

 

Chaitanya ILCR
Giga Patron

Hi @pranayreddy ,

 

it's better to go with onSubmit client script in this scenario(even better go with a before insert/update BR)

 

ChaitanyaILCR_1-1751259004273.png

 

function onSubmit() {
    var total = 0;
    var subjects = ['u_telugu', 'u_hindhi', 'u_english', 'u_maths', 'u_science', 'u_social']
    for (i in subjects) {
        var tempValue = g_form.getValue(subjects[i]);
        if (tempValue) {
            total += parseInt(tempValue) || 0;
        }
    }
    g_form.setValue('u_total', total);

}

 

with onChange you have to create 6 onchange client scripts with 6 subjects 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

 

Ankur Bawiskar
Tera Patron

@pranayreddy 

you can use before update business rule and update the total

If my response helped please mark it correct and close the thread so that it benefits future readers.