How to fix null return value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago - last edited 2 hours ago
Hi All,
Here I'm returning sysID from script include and calling that in table filler condition, but it is always showing null
Script Include : client callable ( Glide AJAX enabled) ,
All application scopes
Roles: public
getBuisnessUnit: function() {
var sysID = '';
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', gs.getUserID());
gr.addQuery('active', true);
gr.query();
if (gr.next()) {
sysID = gr.getValue('u_business_unit');
}
//return sysID.toString();
return 'ac26c204870221003ff35d88e3e3ec61';
},
return 'ac26c204870221003ff35d88e3e3ec61'; testing Purpose just returning one sysid , even that also but still NULL value showing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hi Supriya,
Technical Analysis: The issue is almost certainly the "Client Callable" checkbox.
Even though you are applying this filter in the browser (Client), the actual Query/Filter evaluation (javascript: code...) happens on the Server Side before the database fetch.
When you mark a Script Include as Client Callable:
It is intended to be called via GlideAjax.
It typically extends AbstractAjaxProcessor.
This configuration often conflicts with the synchronous execution required by the standard Condition Builder/Filter parser, resulting in a NULL return in this context.
The Solution
1. Uncheck "Client Callable" Go to your Script Include getUserDetail and uncheck the "Client Callable" box.
Note: If you are using this same script for GlideAjax calls in other Client Scripts, you should split them into two separate Script Includes: one for the Filter (Server) and one for Ajax (Client).
2. Standardize the Script Structure Ensure your Script Include looks like a standard Class, not an Ajax processor.
var getUserDetail = Class.create(); getUserDetail.prototype = { initialize: function() { }, getBuisnessUnit: function() { // Your logic here var sysID = ''; var gr = new GlideRecord('sys_user'); gr.addQuery('sys_id', gs.getUserID()); gr.addQuery('active', true); gr.query(); if (gr.next()) { sysID = gr.getValue('u_business_unit'); } // Ensure you return a String return sysID ? sysID.toString() : ''; }, type: 'getUserDetail' };
3. Small Observation (Typos) I noticed a typo in your function name: getBuisnessUnit (extra 's' before 'n', missing 's' after).
Your Call: getBuisnessUnit()
Correct Spelling: getBusinessUnit()
Make sure the function name in the Script Include exactly matches the one in your filter string, otherwise it will also return NULL.
Summary: Filters require Server-Side Script Includes. Uncheck "Client Callable", and it should return your SysID correctly.
If this solves the NULL return issue, please mark it as Accepted Solution.
Best regards,
Brandão.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago - last edited an hour ago
Hi
Thanks for your reply,
still null value coming
Server :
var getBusinessUnit = Class.create();
getBusinessUnit.prototype = {
initialize: function() {},
businessunit: function() {
return 'ac26c204870221003ff35d88e3e3ec61';
},
type: 'getBusinessUnit'
};
Callable :
var getUserDetail = Class.create();
getUserDetail.prototype = Object.extendsObject(AbstractAjaxProcessor, {
businessunit: function() {
return 'ac26c204870221003ff35d88e3e3ec61';
},
type: 'getUserDetail'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hi Supriya,
Great job splitting the scripts! Your code logic for the Server-side Script Include (getBusinessUnit) is now perfectly structured for a filter.
Since it is still returning NULL, the issue is no longer the code itself, but likely a naming mismatch or access issue. The filter cannot "find" your class.
Let's debug this in 1 minute using "Scripts - Background":
The filter is just a UI wrapper. To find the root cause, we need to run the script directly on the server.
Navigate to System Definition > Scripts - Background.
Paste the exact line you are trying to use in the filter and wrap it in a print statement:
JavaScriptgs.info('Test Result: ' + new global.getBusinessUnit().businessunit());
Click Run script.
Scenario A: You see an Error (e.g., "is not a function" or "undefined")
Cause: The system cannot find the Script Include. Fix: Check the Name field on the Script Include record.
The record Name in the list view MUST be exactly getBusinessUnit.
If the record is named GetBusinessUnit (Capital G) but your script says var getBusinessUnit (lowercase g), it will fail. They must match case-sensitively.
Ensure the API Name is indeed global.getBusinessUnit.
Scenario B: It prints the ID (Test Result: ac26...)
Cause: The Script Include works, but the Filter syntax is slightly off. Fix:
Remove the semicolon ; from the end of your filter string.
Try removing the global. prefix if you are operating in the Global scope.
Try: javascript:new getBusinessUnit().businessunit()
Summary: If Scripts - Background cannot see it, the Filter definitely won't. Please run that test and let me know the result!
If this helps you isolate the issue, please mark it as Accepted Solution.
Best regards, Brandão.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
52m ago
I already tried in BackGround script
I tried in background script
gs.info(new getBusinessUnit().businessunit());
gs.info(new getUserDetail().businessunit());
*** Script: ac26c204870221003ff35d88e3e3ec61
*** Script: ac26c204870221003ff35d88e3e3ec61
I got perfectly in background script , not at filters side.
javascript:new getBusinessUnit().businessunit()
javascript:new getUserDetail().businessunit()
