- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2025 03:10 AM
We are trying to execute script include from business rule and for testing tried from background script also.
Script include is not client callable as we are calling it from server side only and Accessible from is 'All application scope'.
We are calling it from global scope only.
When we print the value of variable before return statement it gives correct value. But when it returns and we are printing the output of script include method it return undefined. We tried by defining static value and returning it gives same result.
return "some sys id"; this statement also gives undefined answer.
Regards,
Dhanashree
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2025 04:42 AM
try this and see
var getOwner = Class.create();
getOwner.prototype = {
initialize: function() {},
getOwner: function(approver) {
var ul, lastMgr, path;
var t = this.getManager(approver);
var exe = t.split(' ');
path = exe[1];
lastMgr = exe[0];
if (path == '') {
ul = approver;
} else if (path == '1000M') {
ul = approver;
} else {
ul = this.getOwner(lastMgr); // Ensure the recursive call returns a value
}
if (ul != '' && ul != undefined) {
gs.log("UL " + ul, 'UL');
return "UL " + ul;
}
},
getManager: function(user) {
var man, path;
var getM = new GlideRecord('sys_user');
if (getM.get(user)) {
if (getM.active == true) {
man = getM.manager;
path = getM.manager.u_org_path.u_path;
return man.toString() + ' ' + path.toString();
}
}
},
type: 'getOwner'
};
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2025 03:30 AM
return "sysid of record"; this statement I have used at the end of script include still getting undefined.
The log message before return statement gives correct value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2025 03:57 AM
undefined means it's not able to call
Sorry but please share some scripts, were you able to replicate that in your PDI?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2025 03:41 AM
Hi @dhanu3
Can you share the script screenshots
Thanks & Regards
Sejal Chavan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2025 04:02 AM
If your script is recursive, ensure that all possible paths in the recursion eventually lead to a return statement. If a condition prevents reaching return, it may result in undefined.
Please mark correct/helpful if this helps you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2025 04:14 AM
If you need assistance on scripts, you need to share your scripts. It has been asked multiple times, but you keep ignoring that question. Without the scripts, we can't help.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark