Issue with Value returned from Script Include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2024 01:10 AM
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]
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2024 03:11 AM
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.
If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2024 03:19 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2024 03:41 AM
Hello to the experts answering, if it is the same answer already existing on a Question, then its better to avoid re-Answering. Thanks.
If my response proves useful, please mark it "Accept as Solution" and "Helpful". This action benefits both the community and me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-21-2024 11:45 AM
I agree, no need to post functionally equivalent answers. Seems to happen often here.