"org.mozilla.javascript.EcmaError: Cannot convert null to an object. "get thrown by Business Rule ( before BR)

Abhishek Kumar8
Tera Contributor

Hi 

Script is throwing an error :"org.mozilla.javascript.EcmaError: Cannot convert null to an object.
Caused by error in sys_script.445cab971b84e4d4170afc4e0d4bcb17.script at line 1"

script :

BR - Before

Insert ( checkbox true)

Update ( checkbox true )

script : 

(function executeRule(current, previous /*null when async*/ ) {

// check pen test complaince status
gs.log("is testing required pen tesingtt" + current.u_pen_test_is_testing_required);
var startdate = new GlideDateTime();
var start1date = startdate.getDisplayValue();
var end1date = '';
var total1date = [];
end1date = current.getDisplayValue('u_pen_test_last_full_test_date');
var totaldiff = gs.dateDiff(start1date, end1date, false);
total1date = totaldiff.toString().split(" ")[0];
// Update Is Testing Required = Yes/No
var pen_test_deviations = '';
var dev = new GlideRecord('u_pen_test_deviations');
dev.addQuery('u_pen_test_deviation_app_id', current.u_pen_test_app_id);
dev.query();
if (dev.next()) {
pen_test_deviations = dev.u_pen_test_deviations.getDisplayValue();
}

})(current, previous);

could you please help on this to fix the warning?

Thanks in advance!

attaching the screenshot of the log.

find_real_file.png

4 REPLIES 4

Sukraj Raikhraj
Kilo Sage

 current.u_pen_test_is_testing_required is probably not the right name of the the variable/field or it's empty. 

Do you check if  current.u_pen_test_is_testing_required) is nil first? 

if(current.u_pen_test_is_testing_required.nil()){

 

      gs.log(" I am Here");

 

      

 

}

http://wiki.servicenow.com/index.php?title=GlideElement#nil

Thank you for your quick reply!

I have added the code and it's returning the same error.

(function executeRule(current, previous /*null when async*/ ) {

// check pen test complaince status
if(current.u_pen_test_is_testing_required.nil()){
gs.log(" I am Here");
}

error : 

find_real_file.png

Anurag Tripathi
Mega Patron
Mega Patron

Run the blank business rule, (comment complete code except first and last line)

then slowly uncomment code, few lines at a time to find which like is throwing the error.

I also recommend to use try catch in such piece of codes.

-Anurag

-Anurag

Abhishek Kumar8
Tera Contributor

I have commented on the codes and uncommented them to check the step by step. I could see that codes are working fine for the if condition but it's breaking while going into the else part. Is there any way to exclude the encoded queries conditions mentioned inside the if and include only conditions not present inside the if statement?

if condition:

if (test_deviations == 'N') {
var test_required_one = new GlideRecord('cmdb_ci_business_app');
test_required_one.addEncodedQuery('application_type!=saas^install_status=10^application_category=1f5328391b6aff085105ea0f6e4bcb78^u_compliance_standardsLIKE***^u_network_typeLIKE***^u_hostingNOT LIKE652600f31b2afb005105ea0f6e4bcbe5');
test_required_one.addQuery('sys_id', current.u_pen_test_app_name);
test_required_one.query();
if (test_required_one.next()) {
current.u_pen_test_is_testing_required = true;

}

else {
current.u_pen_test_is_testing_required = false;

}

var test_required_two = new GlideRecord('cmdb_ci_business_app');
test_required_two.addEncodedQuery('application_type!=saas^install_status=10^application_category=1f5328391b6aff085105ea0f6e4bcb78^data_classification=confidential^ORdata_classification=restricted^ORdata_classification=internal^ORdata_classification=public^u_compliance_standardsLIKE***^u_network_typeLIKEb21d46dbdb980cd0f2212418489619b6^ORu_network_typeLIKE***^u_hostingNOT LIKE652600f31b2afb005105ea0f6e4bcbe5');
test_required_two.addQuery('sys_id', current.u_pen_test_app_name);
test_required_two.query();
if (test_required_two.next()) {
current.u_pen_test_is_testing_required = true;
}

else {
current.u_pen_test_is_testing_required = false;

}

}

else {
current.u_pen_test_is_testing_required = false;

}

 

watch on the "is testing required": value received from the client: false but it's not setting the is testing required field to false or vice versa.

Any help on this is really appreciated.

 

Thanks in advance!.