JavaScript evaluation returned: NaN in script error in Data collection Job

Sarath12
Giga Contributor

I was trying to calculate the business duration in days using a script which used for breakdown mapping of 'business duration age' breakdown with 'business duration' field in Incident table.
My daily collection job ran without any error but when I ran a historical data collection it threw an error.

 

My script is,

var diff=function(x,y){return parseInt(y) - parseInt(x);};
var days=function(x,y){return diff(x,y)/(24*60*60*1000);};
days(0,current.business_duration);

 

I know this is a twisted way to get this done. I couldn't find another way and since i need the records to be shown, i can't use formula indicator.

Below is the error message that I got.

Error during JavaScript evaluation com.snc.pa.dc.ScriptException: JavaScript evaluation returned: NaN in script: var diff=function(x,y){return parseInt(y) - parseInt(x);};
var days=function(x,y){return diff(x,y)/(24*60*60*1000);};
days(0,current.business_duration);
at com.snc.pa.dc.Script.handleException(Script.java:182)
at com.snc.pa.dc.Script.evaluate(Script.java:149)
at com.snc.pa.dc.Script.evaluate(Script.java:125)
at com.snc.pa.dc.DataCollector.evaluateScript(DataCollector.java:580)
at com.snc.pa.dc.DataCollector.collect(DataCollector.java:657)
at com.snc.pa.dc.DataCollector.collect(DataCollector.java:505)
at com.snc.pa.dc.DataCollector.collect(DataCollector.java:384)
at com.snc.pa.dc.DataCollectorJob.collect(DataCollectorJob.java:445)
at com.snc.pa.dc.DataCollectorJob.collectWithMutex(DataCollectorJob.java:315)
at com.snc.pa.dc.DataCollectorJob.execute(DataCollectorJob.java:300)
at com.glide.schedule.JobExecutor.lambda$executeJob$0(JobExecutor.java:129)
at com.snc.db.data_replicate.replicator.DataReplicationAdvisors.runInOriginatorContext(DataReplicationAdvisors.java:73)
at com.glide.schedule.JobExecutor.lambda$inDataReplicationContext$2(JobExecutor.java:159)
at com.glide.schedule.JobExecutor.executeJob(JobExecutor.java:132)
at com.glide.schedule.JobExecutor.execute(JobExecutor.java:116)
at com.glide.schedule_v2.SchedulerWorkerThread.executeJob(SchedulerWorkerThread.java:338)
at com.glide.schedule_v2.SchedulerWorkerThread.lambda$process$0(SchedulerWorkerThread.java:220)
at com.glide.worker.TransactionalWorkerThread.executeInTransaction(TransactionalWorkerThread.java:35)
at com.glide.schedule_v2.SchedulerWorkerThread.process(SchedulerWorkerThread.java:220)
at com.glide.schedule_v2.SchedulerWorkerThread.run(SchedulerWorkerThread.java:101)
Caused by: java.lang.Exception: JavaScript evaluation returned: NaN
... 19 more

1 ACCEPTED SOLUTION

Hey,

Try using something like this:

var diff=function(x,y){

    return y - x;

};
var days=function(x,y){

return diff(x,y)/(24*60*60*1000);

};
days(0,current.business_duration.getGlideObject().getNumericValue());

Best Regards
Aman Kumar

View solution in original post

3 REPLIES 3

Aman Kumar S
Kilo Patron

you need to use Number() instead of parseInt() also getGlideObject().getNumericValue() to get duration into seconds.

 

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂

Best Regards
Aman Kumar

I tried using Number() instead of ParseInt() and it didn't work.

Hey,

Try using something like this:

var diff=function(x,y){

    return y - x;

};
var days=function(x,y){

return diff(x,y)/(24*60*60*1000);

};
days(0,current.business_duration.getGlideObject().getNumericValue());

Best Regards
Aman Kumar