Error during JavaScript evaluation com.snc.pa.dc.ScriptException: JavaScript evaluation returned

shawshipra
Tera Expert

Hello All,

 

Trying to create breakdown mapping on HR case - Metric Instance database view to get breakdown on task type

 

Below is the snapshot of script

 

shawshipra_0-1670881429036.png

 

but on running the data collector job i am getting error stating - " Error during JavaScript evaluation com.snc.pa.dc.ScriptException: JavaScript evaluation returned: Undefined in script:"

 

Please suggest

 

5 REPLIES 5

Nicholas Deeks
Tera Contributor

Hi @shawshipra 

 

A breakdown script always needs to return something. We had the same issue where the solution was to create a variable that returned the sysid if we found something and an empty string if we didn't.

 

The error is actually saying that your return is undefined in those cases where no record was found. 

 

So for your script this would look something like this:

 

function getTaskType() {

var sysIdToReturn = "";
var grTable = new GlideRecord('sys_db_object');
grTable.addQuery('name', current.mi_table);
grTable.query();
if (grTable.next()) {
sysIdToReturn = grTable.sys_id;
}

return sysIdToReturn;

}
getTaskType();