Issue with Value returned from Script Include

gravi3609
Tera Contributor

Hi,

I am calling a script include function from background script . The value returned from script include is coming as [object Object].However when I add log in script include, it is actuialluy a string. 

Please let em know what is missing here.

 

Script include

 

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

    myPagetester: function() {
        var referer = GlideTransaction.get().getRequest().getHeader("referer");
		var ty = JSON.stringify(referer);
		gs.info("the sc messge is : " + ty);
        return ty;
    },

    type: 'TestPageNameUtil'
};

 

Background script:

 

var ty = new global.TestPageNameUtil();
ty.myPagetester();

gs.info("the tester page is : " + ty);

 

Here is the output:

*** Script: the sc messger is : "https://dev266933.service-now.com/sys.scripts.modern.do"
*** Script: the tester page is : [object Object]

 

5 REPLIES 5

Tony Chatfield1
Kilo Patron

Hi, to confirm the type of your variable you should use 'typeof'

JavaScript typeof (w3schools.com)

 

gs.info('My variable type ' + typeof yourVariable);