Cannot convert null to an object error in script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2019 04:55 AM
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
But same code run in a test environment it working fine.
Anyone faced this type of issue, please guide me.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2019 05:07 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2019 05:47 AM
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.