JavaScript Error in Pentaho - Cannot call method “toUpperCase” of null

二次信任 提交于 2019-12-11 16:51:57

问题


// Sets all the letters as uppercase

var str = ae_a_asset_e$manufacture_code.toUpperCase();
var str2 = ae_a_asset_e$serial_no.toUpperCase();
var str3 = ae_a_asset_e$manu_part_number.toUpperCase();
var str4 = ae_a_asset_e$region_code.toUpperCase();
var str5 = ae_a_asset_e$fac_id.toUpperCase();

Any idea how to fix this? I would think there would have to be a way to say if value = null then don't worry about it.


回答1:


First you have to think whether it is correct that some values are null or not, such as ae_a_asset_e$manufacture_code.

If they can be null you can access them in a safe way like this (extend this code to all other vars as required):

var str = ae_a_asset_e$manufacture_code ? ae_a_asset_e$manufacture_code.toUpperCase() : "";

If they cannot be null then, your should check your data integrity first and then run this script (assuming they are never null).



来源:https://stackoverflow.com/questions/48407801/javascript-error-in-pentaho-cannot-call-method-touppercase-of-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!