Receiving NaN error, When numbers or divided (other than zero) and even Zero divided by number get same Error

farci
Mega Expert

Hi All,

I am receiving NaN error when two numbers are getting divided and even Zero divided by number gets me Nan Error. Below are the screenshot of error and the scripts.

I am trying to divide numerator with denominator and arriving at the result.

find_real_file.png

Here is the code

// SERVICE REQUEST

if(current.backup_type=="Service Request"){

var cal = new GlideAggregate('x_pm_service_request_backup_template');

ret = cal.addQuery('pri',current.priority_one);

ret.addOrCondition('pri',current.priority_two);

cal.addQuery('service_provider_name',current.sp_name);

cal.addQuery('si_sec',"Met");

cal.addQuery('service_month',current.serv_mon);

cal.addAggregate('COUNT');

cal.query();

var numerator = 0;

if(cal.next())

numerator = cal.getAggregate('COUNT');

//SERVICE REQUEST EXCEPTION

var exp = new GlideAggregate('x_pm_service_request_backup_template');

var pri = cal.addQuery('pri',current.priority_one);

pri.addOrCondition('pri',current.priority_two);

var ret= exp.addQuery('exp_status',"Approved");

ret.addCondition('si_sec',"Not Met");

exp.addQuery('service_provider_name',current.sp_name);

exp.addQuery('service_month',current.serv_mon);

exp.addAggregate('COUNT');

exp.query();

var exception = 0;

if(exp.next())

exception = exp.getAggregate('COUNT');

var res1= (parseInt(numerator) + parseInt(exception));

current.si_num = res1.toFixed(0);

var cal1 = new GlideAggregate('x_pm_service_request_backup_template');

//cal1.addQuery('pri',current.priority_one);

var ret = cal1.addQuery('pri',current.priority_one);

ret.addOrCondition('pri',current.priority_two);

cal1.addQuery('service_provider_name',current.sp_name);

var addups = cal1.addQuery('si_sec',"Not Met");

addups.addOrCondition('si_sec',"Met");

cal1.addQuery('service_month',current.serv_mon);

cal1.addAggregate('COUNT');

cal1.query();

var denominator = 0;

if(cal1.next())

denominator = cal1.getAggregate('COUNT');

current.si_deno = denominator;

var res = (res / denominator) * 100;

current.si_vr = res.toFixed(2);

current.update();

action.setRedirectURL(current);

}

Appreciate your quick response

Regards,

Narmi

1 ACCEPTED SOLUTION

you can use the below code to convert



var a =   g_form.getValue("short_description");


var b =   g_form.getValue("description");


var c = (+a) /(+b);


alert("hello"+c);


View solution in original post

6 REPLIES 6

Chandu Telu
Tera Guru
Tera Guru

HI Narmi,



is this two fields are string or integers


Hi Chandu,



All the three fields are string.



Regards,


Narmi


Directly if you divide the strings you will get NAN error



you need convert them into integers you can use parseInt


Check the below link it will help you



javascript - How to add two strings as if they were numbers? - Stack Overflow