- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2022 03:53 PM
Hello,
We have a script include in Global scope that works like a charm when called from the client.
I would like to extend a small piece of functionality in this script include. So as a first step I created a new script include that is basically a "copy" of the existing script in all ways, except the new one is in my scoped application. Before I add functionality I want to confirm this "copy" is working like the original.
Thus when calling the new script, I call:
my_scoped_app.copied_script_include
Instead of:
global.original_script_include
However, although the original script include works, the copied script include returns null to the client.
Things I've tried:
1. I made sure both the original and the copy have exactly the same script.
2. I made sure both the original and the "copy" are Client Callable.
3. I tried changing the "Accessible from" attribute on the copied script include from "This Application Scope Only", "all application scopes" (like the original script include), but this didn't help.
4. I even tried calling 'global.copied_script_include'. That didn't work (no big surprise there). The comforting thing is the client got a 404 not found. So the 'my_scoped_app.copied_script_include' reference is reaching my copied script include.
Do I really have to put my copied script include in global scope to get it to work?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2022 01:10 PM
Yes, I logged the return value just before the return statement. The return value printed beautifully if I JSON stringified it.
return new JSON().encode(answer);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2022 01:22 PM
This makes sense. Having not seen your scripts and as a clean code / best practice example and learning experience, you should always declare and initialize a variable in a Script Include, then return the value of that variable - both outside of any loops or if statements, so like:
var answer = '';
- or -
var answer = 'empty';
at the beginning of the function, and
return answer;
at the end of the function. By doing this, you should always get a result in the client, and if it's blank or 'empty' or whatever, then you know the meat of the script isn't doing what you expect, so you can log 'answer' right before the return to see if it has a value without further manipulating it after the fact. By using
return new JSON().encode(answer);
you're changing the value of 'answer' and returning it in the same step, so if it's not working, it's not clear which action is failing. Since your new script is in a different scope, you would want to use
return new global.JSON().encode(answer);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2022 04:27 PM
Are there functions in the script include which calls another script include?
That could be the issue.
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2022 09:56 AM
Hi @SanjivMeher Thanks for the question. No there are no functions in the script include calling another script include.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-18-2022 10:37 AM
Is you client script and script include in same scope?
Did you try creating another copy with Accessible from as "All application scope"?
Make sure changing the script name in the script include code. Usually it auto-corrects based on the name of the new script include, but you never know.
Please mark this response as correct or helpful if it assisted you with your question.