"Copy" of working script include doesn't work

Michael Butak1
Tera Contributor

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?

 

1 ACCEPTED SOLUTION

Yes, I logged the return value just before the return statement.  The return value printed beautifully if I JSON stringified it.  

I can't explain why, but for some reason I had to change this:
 
//encode the returned query object as a json string and return it to the client
return new JSON().encode(answer);
 
to:
 
return JSON.stringify(answer);
 
No idea why but that fixed it.
 
 

View solution in original post

8 REPLIES 8

Brad Bowman
Kilo Patron
Kilo Patron

Hi Micheal,

Go with calling it the way you did, then add some logging - at the beginning to confirm that it is running, and whatever is happening at each step, so you can see where it stops working - calling a method that isn't available in your scope, or whatever.

Hi @Brad Bowman  ,

Thanks for the tip.  I added logging and I can see my script invoked, and I can see it successfully retrieve a record from a database table.  I don't see it failing anywhere, and yet the client still receives a null.  

Are you passing a value from the client to the Script Include, and if so does it show when logged as expected?  Did you log the return value right before the return statement?  It may help to post your scripts (use the insert code icon </>).

Yes, I logged the return value just before the return statement.  The return value printed beautifully if I JSON stringified it.  

I can't explain why, but for some reason I had to change this:
 
//encode the returned query object as a json string and return it to the client
return new JSON().encode(answer);
 
to:
 
return JSON.stringify(answer);
 
No idea why but that fixed it.