Question
· Mar 26, 2019

Iterating Ens.Request to create a JSON

Let's say we have a class 

AbcRequest extends Ens.Request, PropertiesBaseAbstractClass(has all my properties common to all request)

Prop1

Prop2 and so on

 

Now in my Business Operation 

I want to make a json dynamically from this request.

Yes obviously I can do is

 

Set requestDefinition = ##class(%Library.CompiledClass).%OpenId("MyCreateRequest")
Set JsonObject    = ##class(%DynamicObject).%New()        

        for i=1:1:requestDefinition.Properties.Count() {  
            Set key            = requestDefinition.Properties.GetAt(i).Name
            Set value        = $property(pRequest,requestDefinition.Properties.GetAt(i).Name)
            Set JsonObject.key = value
          
        }
        Set requestString        = JsonObject.%ToJSON()

This makes a json {"key":""}

Discussion (3)1
Log in or sign up to continue