Cannot convert null to an object (scripts background)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2017 05:07 PM
Very simply put, I am running a query in scripts background and am getting the error 'cannot convert null to an object'. I'm not sure which piece is pulling back null. Can anyone advise what I can change in the script?
The logs say the error is in line 5. - 'org.mozilla.javascript.EcmaError: Cannot convert null to an object.'
var gr = new GlideRecord('x_access_request');
gr.query();
while (gr.next()){
if (gr.getValue('receivers').contains(gr.getValue('opened_by'))) {
gs.print('Number : ' + gr.number);
gs.print('Requestor : ' + gr.opened_by);
gs.print('Receivers : ' + gr.getValue('receivers'));
}
}
TIA!
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-22-2019 04:30 AM
var gr = new GlideRecord('x_access_request');
gr.query();
while (gr.next()){
var receivers = gr.getValue("receivers");
if (receivers && receivers.contains(gr.getValue('opened_by'))) {
gs.print('Number : ' + gr.number);
gs.print('Requestor : ' + gr.opened_by);
gs.print('Receivers : ' + gr.getValue('receivers'));
}
}
the above changes should make it work.
1. gr.getValue("") was not expected to return null - but that seems to be happening here AND
2. null.contains() is causing the code to fail
Better to do a null check on the object before using it to invoke a property on it - a general safe coding practice.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-21-2020 10:29 PM
Hi All,
I am also getting a similar error while enhancing a catalog item and getting the following error. Can anyone of you please advise me on this. There is a variable called "affected_ci_12" in my catalog item and it is mandatory and it is being filled but unfortunately each time the form is submitted, I am getting the below error and this particular variable question is appearing empty in both RITM as well as in task level. Please help.
Exception (TypeError: Cannot convert null to an object. (sys_script_include.4c6855377522d0004c6382de47d76747.script; line 2)) occured while evaluating'Condition: gup('sysparm_changeset',gs.getSession().getStack().top())!=''' in business rule 'Propose relationship query' on u_propose_relationships:Created ; skipping business rule