NullPointerException when calling a script include in Business rule condition field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2017 04:28 AM
Hi experts,
Actually I'm facing a weird issue; I have a before query business rule which i want to restrict its execution only to some cases.
That said, i have set up a script include in which i build a condition that return true in those specific cases.
Then i have called my script include method in the condition field of the business rule using new ScriptName().methodName(param)
When the business rule runs i got the error:
java.lang.NullPointerException Caused by error in Business Rule |
Have you ever encountred such an error?
Any help will be highly apreciated, thanks in adavnce
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2017 04:35 AM
Hi Layla,
Any issue of scoped app you think of here.
Can you check whether you can call that script include and get true/false in background script.
Also if this is not working then add those line as first line of code in the business rule script and if true run the query business rule condition.
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2017 05:32 AM
A null pointer exception is most commonly caused by dot-walking where part of the dot-walk path is null. For example, if "manager" is an empty value and I try to do something like this from the sys_user record...
var dept = current.manager.department;
You'll get a null pointer exception. The prevent this would look like:
var dept = '';
if (manager) {
dept = current.manager.department;
}
Best practice: Check your reference fields for valid values before using them.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-25-2017 07:45 AM
Hi
Thanks for your quick replies.
Actually here is the code in my script include:
var buildMinusEventsCondition = Class.create();
buildMinusEventsCondition.prototype = {
initialize: function() {
},
getCondition: function () {
var uri = gs.action.getGlideURI();
var isIncidentList = uri.toString().indexOf('incident_list.do'),
isIncidentRelList = uri.toString().indexOf('sys_is_related_list'),
isIncident = uri.get('sys_target'),
isSlushBucket = uri.toString().indexOf('slushbucket.do'),
isIncidentRecord = uri.toString().indexOf('sysparm_collectionID');
return isSlushBucket == -1 && (isIncident == 'incident' || isIncidentList != -1 || isIncidentRelList != -1);
},
type: 'buildMinusEventsCondition'
};
I doubt the error is comming from the line var uri = gs.action.getGlideURI(); even it's showing the exact URI in logs
any idea!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-26-2017 01:35 AM
Hi all,
In fact the issue is coming from the use of the API gs.action.getGlideURI()
Even it gives the correct value of the URI the exception is thrown.
I have removed the call of the script include from the condition field, now the exception is not visible to the user and the business rule is working but the exception is still present in logs.
I dont understand this behavior!