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  



14 REPLIES 14

I did try, but no luck

Ankur Bawiskar
Tera Patron

@Supriya25 

Ensure in your script include you are setting this checkbox as True

Sandbox enables - True

Client callable - True

AnkurBawiskar_0-1769924402844.png

 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Supriya25 

Hope you are doing good.

Did my reply answer your question?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Omg I've been trying to solve this issue all day and changing Sandbox enabled to True fixed it for me! Thank you so much!

Tejas Adhalrao
Tera Guru

Hi @Supriya25  , recently i have done similar task .

Your Script Include is Client Callable

but this javascript:new global.getUserDetail().getBusinessUnit()   - is a server-side execution.That is why it's returning NULL.

 

Remove : Client Callable checkbox (make sure that your script include is server side) 

make sure that Script include All application scopes

important : Sandbox enabled to True

make sure enable snad

EX:

var getUserDetail = Class.create();
getUserDetail.prototype = {

    getBusinessUnit: function() {

        var gr = new GlideRecord('sys_user');
        gr.addQuery('sys_id', gs.getUserID());
        gr.addQuery('active', true);
        gr.query();

        if (gr.next()) {
            return gr.getValue('u_business_unit');
        }

        return '';
    },

    type: 'getUserDetail'
};

 

call your script include  

javascript:new getUserDetail().getBusinessUnit()  

OR

javascript:new global.getUserDetail().getBusinessUnit()

 

 

 

 If you found my solution helpful, please mark it as Helpful or Accepted Solution...!

thanks,

tejas

Email: adhalraotejas1018@gmail.com

LinkedIn: https://www.linkedin.com/in/tejas1018