What’s the trick to build a JSON string

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Rennur
Posts: 1191
Joined: Thu Mar 01, 2012 5:13 am
Location: Sydney, Australia

Re: What’s the trick to build a JSON string

Post by Rennur »

Exposing data is not an issue. Like Jaymer said you are only exposing it to yourself (URL_CONTENTS call can always use localhost).
This confirms it for me it's the best solution.

LIMITATION:
Exposing parent BOs with child references, the child references are generated in JSON within each instance of parent BOs.
But if you expose child BOs that have a parent BO, only the first child BO has a JSON reference to the Parent BO, the rest of the child instances do not have this JSON ref.

In the JSON example below there are 4 child refs, 2 per parent BO called Job.

{
"response": [

CHILD BOs for the first parent Job
{
"Status": "PENDING",
"Name": "Item 1",
"Job": {
"Status": "BOOKED",
"JobReference": "5921409"
},

"JobReference": "5921409",
"ItemId": "5921410"
},

(Second child reference missing Job JSON ref)
{
"Status": "PENDING",
"Name": "Item 2",
"JobReference": "5921409",
"ItemId": "5921411"
},

CHILD BOs for the second parent Job
{
"Status": "PENDING",
"Name": "Item 3",
"Job": {
"Status": "BOOKED",
"JobReference": "5922318"
},

"JobReference": "5922318",
"ItemId": "5922319"
},
(Again, the second child reference missing Job JSON ref)
{
"Status": "PENDING",
"Name": "item 4",
"JobReference": "5922318",
"ItemId": "5922320"
}
]
}

Support, is this normal behaviour that only the first child instance BO has the JSON ref to the parent BO?
Last edited by Rennur on Thu Jul 19, 2018 6:39 am, edited 1 time in total.
aware_support
Posts: 7525
Joined: Sun Apr 24, 2005 12:36 am
Contact:

Re: What’s the trick to build a JSON string

Post by aware_support »

No, it's not normal. If you are sure that you have done everything correctly please send your BSV to us and let us know how to reproduce the problem in this BSV
Aware IM Support Team
Rennur
Posts: 1191
Joined: Thu Mar 01, 2012 5:13 am
Location: Sydney, Australia

Re: What’s the trick to build a JSON string

Post by Rennur »

BSV emailed.
Rennur
Posts: 1191
Joined: Thu Mar 01, 2012 5:13 am
Location: Sydney, Australia

Re: What’s the trick to build a JSON string

Post by Rennur »

if you expose child BOs that have a parent BO, only the first child BO has a JSON reference to the Parent BO, the rest of the child instances do not have this JSON ref.
Identified as a bug, fixed in the next build.
Jaymer
Posts: 2448
Joined: Tue Jan 13, 2015 10:58 am
Location: Tampa, FL
Contact:

Re: What’s the trick to build a JSON string

Post by Jaymer »

Rennur
Thanks for putting some effort into this.
I think thats amazing that it will output the JSON array for child recs.
And if you use the Data Transfer Object described by Ben (which I just did for an output to Excel) (and NOW that data could be exposed to anyone via REST), then you can build child recs for exactly whats required and Voila (hopefully).
I'll wait until that next build and then I'll dig into this method.
thx
Click Here to see a collection of my tips & hacks on this forum. Or search for "JaymerTip" in the search bar at the top.

Jaymer
Aware Programming & Consulting - Tampa FL
Rennur
Posts: 1191
Joined: Thu Mar 01, 2012 5:13 am
Location: Sydney, Australia

Re: What’s the trick to build a JSON string

Post by Rennur »

Thanks for putting some effort into this.
No probs, REST is now essential part of the app dev world.
Last edited by Rennur on Tue Jul 31, 2018 12:12 am, edited 1 time in total.
Rennur
Posts: 1191
Joined: Thu Mar 01, 2012 5:13 am
Location: Sydney, Australia

Re: What’s the trick to build a JSON string

Post by Rennur »

Aware IM Service will not work if there are more than 1000 records in the database found by the Implementing Process. It will return a blank result.
In other words, the URL_CONTENTS will not get the JSON parameter from the service when there are more than 1000 records in the database for that BO.

Normally you wouldn't need to generate such a long string.

The FIND function in the implementing process should have the IN BATCHES OF suffix in the query to ensure you receive a JSON response, and to ensure you can generate the JSON string for any amount of records.
johntalbott
Posts: 619
Joined: Wed Jun 17, 2015 11:16 pm
Location: Omaha, Nebraska
Contact:

Re: What’s the trick to build a JSON string

Post by johntalbott »

Rennur wrote:What should the process look like?

FIND Objects specified in Service Reply
FIND BO storing the JSON string
BO.JSON=URL_CONTENTS('REST URL ADDRESS')
What's the use case for this approach?
VocalDay Solutions - Agility - Predictability - Quality

We specialize in enabling business through the innovative use of technology.

AwareIM app with beautiful UI/UX - https://screencast-o-matic.com/watch/crfUrrVeB3t
Rennur
Posts: 1191
Joined: Thu Mar 01, 2012 5:13 am
Location: Sydney, Australia

Re: What’s the trick to build a JSON string

Post by Rennur »

I was testing exposing a REST service in version 6.0 and consuming the service in 8.1.
johntalbott
Posts: 619
Joined: Wed Jun 17, 2015 11:16 pm
Location: Omaha, Nebraska
Contact:

Re: What’s the trick to build a JSON string

Post by johntalbott »

Rennur wrote:I was testing exposing a REST service in version 6.0 and consuming the service in 8.1.
Thanks
VocalDay Solutions - Agility - Predictability - Quality

We specialize in enabling business through the innovative use of technology.

AwareIM app with beautiful UI/UX - https://screencast-o-matic.com/watch/crfUrrVeB3t
Rennur
Posts: 1191
Joined: Thu Mar 01, 2012 5:13 am
Location: Sydney, Australia

Re: What’s the trick to build a JSON string

Post by Rennur »

aware_support wrote:
There is a LOT of parameters you may want to provide to the function that converts a business object to JSON. This is because there are quite a few subtleties in how a JSON string can be generated from an Aware IM record (or records) - how empty values are encoded, how names are mapped etc. All of this has already been done when you expose a REST-ful service and define its response to have JSON format. Therefore, the official suggestion is to use a service and URL_CONTENTS function to do this
Convert any Reference Attribute to JSON and store the JSON string using advance script feature.
Since you can apply query filters on references, you can convert any required data into a JSON string.

Table to JSON
(No BSV to share just yet)
Post Reply