Why I am getting "NaN" values though the fields are decimal type?

Virendra K
Kilo Sage

Hi,

I have below code its written on BR.

var gr = new GlideRecord("rm_story");
gr.addQuery("parent",current.sys_id);
gr.query();
var TP=0;
var BP=0;
var RP=0;
while (gr.next()) {
TP=TP+ parseFloat(gr.getValue('u_points'));
BP=BP+ parseFloat(gr.getValue('u_burndown_points'));
}
RP=TP-BP;
gs.addInfoMessage(TP + ' ' + BP + ' ' + RP);

=============================================================

"u_points" and "u_burndown_points"  fields are decimal by type and I parsed those values as well.

but after executing the code I am getting below values (snap),

find_real_file.png

What is the reason? 

1 ACCEPTED SOLUTION

Jon Barnes
Kilo Sage

decimal fields will still allow NULL values, and since getValue() will return NULL if the field is blank, I believe you can resolve this by modifying your script as follows:

 

var gr = new GlideRecord("rm_story");
gr.addQuery("parent",current.sys_id);
gr.query();
var TP=0;
var BP=0;
var RP=0;
while (gr.next()) {
  if (!gr.u_points.nil()) {
    TP=TP+ parseFloat(gr.getValue('u_points'));
  }
  if (!gr.u_burndown_points.nil()) {
    BP=BP+ parseFloat(gr.getValue('u_burndown_points'));
  }
}
RP=TP-BP;
gs.addInfoMessage(TP + ' ' + BP + ' ' + RP);

View solution in original post

3 REPLIES 3

Jon Barnes
Kilo Sage

decimal fields will still allow NULL values, and since getValue() will return NULL if the field is blank, I believe you can resolve this by modifying your script as follows:

 

var gr = new GlideRecord("rm_story");
gr.addQuery("parent",current.sys_id);
gr.query();
var TP=0;
var BP=0;
var RP=0;
while (gr.next()) {
  if (!gr.u_points.nil()) {
    TP=TP+ parseFloat(gr.getValue('u_points'));
  }
  if (!gr.u_burndown_points.nil()) {
    BP=BP+ parseFloat(gr.getValue('u_burndown_points'));
  }
}
RP=TP-BP;
gs.addInfoMessage(TP + ' ' + BP + ' ' + RP);

Thanks Jon for your quick reply. It worked.

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI,

 

Instead of Parse can you use Number.

 

Thanks,
Ashutosh