How to fix null return value

Supriya25
Tera Guru

Hi All,

Here I'm returning sysID from script include and calling that in table filler condition, but it is always showing null 

Supriya25_0-1769804158207.png

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  



8 REPLIES 8

Hi Supriya,

I noticed in your screenshot that you are testing both scripts simultaneously using an OR condition.

This might be the cause. If the second script (getUserDetail - the Client Callable one) fails to parse correctly (because it extends AbstractAjaxProcessor, which is not friendly to List Filters), it can break the entire query, causing the system to return NULL even if the first script is correct.

Please try this exact single test:

  1. Clear the filter completely.

  2. Add only one condition (do not use OR).

  3. Use the Server-Side script (the one that worked in Background).

  4. Type manually: Sys ID | is | javascript:new getBusinessUnit().businessunit()

By removing the "Client Callable" script from the equation, you allow the valid script to run without interference.

If simplifying the filter solves it, please mark it as Accepted Solution.

Best regards, Brandão.

Hi ,

I did try that as well 

Supriya25_0-1769809661089.png

 

Supriya25_0-1769809160983.png


background script :

gs.info("Server : " + new global.getBusinessUnit().businessunit());

Result :
*** Script: Server : ac26c204870221003ff35d88e3e3ec61


Script Include :

var getBusinessUnit = Class.create();
getBusinessUnit.prototype = {
    initialize: function() {},

    businessunit: function() {
        return '70c0b9c593fafe101a1bf6fa3d03d663';
    },

    type: 'getBusinessUnit'
};


 

Hi Supriya,

Since the script works perfectly in the background, we need to perform one specific test to rule out a likely cause: Data Type Mismatch.

  • The Problem: The operator "is one of" technically expects a List/Array of values. Your script returns a single raw String.

  • The Test: Please change the operator in the filter from "is one of" to "is".

Why? Sometimes the filter parser fails to convert a single string return into the array format required by "is one of", resulting in NULL. By switching to "is", we align the operator with your exact return type (String).

Please try this single change and let me know the result.

Best regards, Brandão.

I tried even , Array method also, still no use.

var getBusinessUnit = Class.create();
getBusinessUnit.prototype = {
    initialize: function() {},

    businessunit: 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.push(gr.getValue('u_business_unit'));
        }

        // Ensure you return a String
        return sysID.toString();
    },

    type: 'getBusinessUnit'
};