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

Akash4
Kilo Sage

Hello Ravi,

You have modified the ty in Background script but calling the original ty instead.

Try this instead:

var ty = new global.TestPageNameUtil();
var output = ty.myPagetester();
gs.info("the tester page is : " + output);

Hope this helps!
Regards, Akash
_____________________________________________________________________________
Please mark it as helpful👍 or Accept Solution✔️ based on the response to your query.

 

Satishkumar B
Giga Sage

Hi @gravi3609 

please update your Background Script. In your background script, you need to capture the return value from myPagetester() and then log that value. 

 

 

var tyUtil = new global.TestPageNameUtil();
var ty = tyUtil.myPagetester(); // Capture the return value from the method

gs.info("the tester page is : " + ty); // Log the captured value

 

 

  • Change: Capture the return value of myPagetester() in a variable (ty).
  • Log: Output the value of ty instead of the tyUtil object.

This will display the correct value returned from your myPagetester() function

……………………………………………………………………………………………………

Please Mark it helpful 👍and Accept Solution✔️!! If this helps you to understand. 

Akash4
Kilo Sage

Hello to the experts answering, if it is the same answer already existing on a Question, then its better to avoid re-Answering. Thanks.

I agree, no need to post functionally equivalent answers. Seems to happen often here.