Question
· Apr 22, 2019

Can a JSON variable (%Library.DynamicObject) ever be a property in an Ens.Request object? Nothing but <INVALID OREF> errors

I have a process that takes data from a CSV file (actually a record mapper object) and creates a nicely formatted JSON string I would love to send this along to a RESTful business operation.  However no matter what I try, I continually get <INVALID OREF> errors when trying to populate the object that extends Ens.Request to give it the JSON string.

I can add strings, other objects, you name it - but stuffing a JSON formatted variable/object into another object I want to send someplace is proving to be an impossibility.

Does anyone have an example of sending an Ens.Request or other object (not an HTTPRequest object - but some other custom object) containing a JSON string to an Operation where the operation ultimately pulls the JSON from the object that was sent to it, makes the REST POST call and sends the response back?

Many thanks in advance! For some reason, every example I see deals with building "services", and the operations used have examples that have everything BUT a JSON payload. Is there some magic words or special dance I am missing? ;-)

(I also included the Cache tag since just the simple act of creating a class that extends %Persistent, having a property that is %Library.DynamicObject or arrays or anything, cannot seem to accept a JSON formatted variable as a value without blowing OREF errors.)

Discussion (8)6
Log in or sign up to continue

Yep. this is exactly what I did. I added a property JSON that was a string, and also added one that was a %Library.DynamicObject. Both of them when I went to assign the JSON array as in:

Set MyObj.JSON=JSONString.%ToJSON()

gave me the INVALID OREF error.

I'm going to try what some others have mentioned - pipe that data from %ToJSON() into a stream property in an object that extends Ens.Request and give that a shot.

Thanks!

For Set MyObj.JSON=JSONString.%ToJSON() to signal <INVALID OREF> then either local variable MyObj is not an oref or local variable JSONString is not an oref.  Make sure that JSONString is really a %DynamicObject by doing a WRITE JSONString before doing the Set command.  The WRITE statement should write some like 99@%Library.DynamicObject .
 

I had this exact issue last week, and this is how I got around it. For clarity, I wanted to pass the Dynamic Object from a process to an operation.

I created my dynamic object within the Process, and then used the %ToJSON Method to put the JSON within a GlobalBinaryStream (which can be passed through the request).

In the Operation, I then use the %FromJSON Method of DynamicAbstractObject to then have the Dynamic Object within the operation.