Create dynamic %Object with object ID
How can I create a JSON with the object ID by using the %Object:$toJSON API?
I have the following piece of code bellow where I create an object reference, create a %Object instance from %fromObject and them I am creating the JSON from $toJSON, but it does not expose the %ID (object id). How is the best approach to create a JSON with the respectives object IDs?
Try { Set tPersonObj = ##class(Data.Person).%OpenId(pId) If $Get(%objlasterror) $$$ThrowStatus(%objlasterror) Set tObj = ##class(%Object).$fromObject(tPersonObj) Write tObj.$toJSON() } Catch ex { Set tSC = ex.Status }
The outcome is:
Write tObj.$toJSON() {"Age":28,"MaritalStatus":"Casada","Name":"Emilia de Souza","Sex":"F"}
I am expecting this:
{"ID":5,"Age":28,"MaritalStatus":"Casada","Name":"Emilia de Souza","Sex":"F"}
Thanks.
In 2016.2, you can do this by overriding %ToDynamicObject in Data.Person as follows:
Thank you very much.
Worked well.
A few side notes...
The correct/best way to create a %Object from a %RegisteredObject (or vice versa) is $compose, not $fromObject (which has been marked as Internal in more recent builds). This is first available in 2016.2.
Also, you can get %RegisteredObjects as JSON more directly:
how to remove the "children" tag name from the json output. can anyone know ?
i need:
[{"ID":1,"Age":21,"EmailID":"","FirstName":"Bhagath","HomeAddress":"","LastName":"Singh"},{"ID":2,"Age":21,"EmailID":"","FirstName":"Bhagath","HomeAddress":"","LastName":"Singh"},]
but i got :
{"children":[{"ID":1,"Age":21,"EmailID":"","FirstName":"Bhagath","HomeAddress":"","LastName":"Singh"},{"ID":2,"Age":21,"EmailID":"","FirstName":"Bhagath","HomeAddress":"","LastName":"Singh"},]}
Please, attach your code that generates this output.
Are you using some provider?
set st = ##class(Workflow.jsonProvider).%ObjectToJSON(tmp)
return st
this is my code which i used for fetch all data from table. correct me if anything wrong , i m new to intersystems. is any possibility to fetch all record through object without write full query?
Output with null
I subscribe to the issue.
Also, how can I use
in Cache Studio 2016.1?
Social networks
InterSystems resources
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue
Log in or sign up
Log in or create a new account to continue