Passing JSON Object to Server (CSP)
Hi there,
I'm passing a JSON object to the server as such:
{"key":"value","key":"value","key":"value"}
From the client:
- Build object
object=JSON.stringify(object)
-pass to server side method as %String
On the server:
s object={}.FromJSON(object)
Instead of getting something like
object=<OBJECT REFERENCE>[2@%Library.DynamicObject]
I get
object="991@%Library.DynamicObject"
I can't access that object using %Get as if says invalid OREF.
I've set the object passed a string to a global and debugged a bit on command line and was successfully able to convert to a dynamic object and use the %Get method to get the value for my key. I'm doing the exact same thing in the server side code but it doesn't work there. Typically, I can do it on the command line, I can do it in the code. I'm not sure what's different between stepping through on the CLI versus running it with they hyperevent. I must be missing something? Can someone offer some advice here?
object="991@%Library.DynamicObject"
Somewhere the object was written into a global and read from it.
@Eduard Lebedyuk Thank you. This IS true since I'm debugging a method defined on CSP page, I'm writing things to a global to check them on the terminal. So that explains that.
How do you know that means that?
it looks like an OREF but it is just a string, try
set obj = [1,2] write obj --> NN@%Library.DynamicArray write $isobject(obj) --> 1 set ^myGlobal = obj set obj=^myGlobal write obj --> NN@%Library.DynamicArray write $isobject(obj) --> 0
see also my answer in https://community.intersystems.com/post/handling-globalcharacterstream-production-service?page=1#comment-189746
How embarrassing for me.
Pro tip: check the names of your keys when you access them :)
Thanks all!
For some more context, I stopped trying to see what was going on by setting globals to debug. I set the %response.TraceDump=1 so I can see the %session variable which is were I'm storing the value to the key of the object:
%session.Data("key")=array.%Get("key")
This is still no working as expected. I even stepped through the code in the command line by calling the zLabel in the INT routine generated from the CSP and it worked as expected there.