Cannot convert null to an object error in script

Raj90
Tera Guru

Hi All,

I write one schedule job it runs daily.

Schedule job:-

 var h=new GlideRecord('u_contract');
       h.addQuery('u_status','Approved');
      h.query();
  while(h.next())
   {
     var date=new GlideDateTime().getDate().getNumericValue();
     var contract=new GlideDateTime(h.u_planned_contract_review).getDate().getNumericValue();
     if(contract==date)
            {
                gs.eventQueue('contract.renewal',h,gs.getUserID(),gs.getUserName());
           }
      }

This schedue job not runs.

Just I wrote the same code in background scripts in Dev environment

I'm faced the below error

find_real_file.png

But same code run in a test environment it working fine.

find_real_file.png

 

Anyone faced this type of issue, please guide me.

 

Thanks

 

 

2 REPLIES 2

Ct111
Tera Sage

Do one thing ,

 

try to print value of contract by writng a line below contract declaration

 

gs.print('Contract is '+contract);

 

 

in both the dev environment in scripts background and in Test.

 

And see if any difference is there or not.

 

Mark my ANSWER as CORRECT and HELPFUL if it helped

Rogers Cadenhe1
Giga Guru

I suspect the problem is that u_planned_contract_review is an empty string in at least one u_contract record in dev but always has a value in the records in test.

If you create a new GlideDateTime() object with an empty string as the argument, a call to getDate() and/or getNumericValue() fails with a null pointer exception. I tested this in my personal dev instance.

In list view, do a Group By of the u_planned_contract_review field of the u_contract table in test and dev to see if any have empty u_planned_contract_review fields.

In any case it wouldn't hurt to test for records where u_planned_contract_review is empty inside your while (h.next()) loop.