Trying to write nested JSON with REST service

Posted by 153102 on 02-Jul-2017 21:07

Hello all,


I am trying my first REST service with 11.6 classic appserver.  I do not seem to be able to nest the PO detail lines within the PO record.  I can do this with a write-json() to file without the REST.  I understand the REST adapter is using write-json so I must be missing something simple.  I have restarted tomcat and appserver,  Thanks for any advice.


Henry


---------------------Definitions


DEFINE TEMP-TABLE ttERP_POShort
FIELD PONbr AS CHARACTER
FIELD Supplier AS CHARACTER
FIELD Shipto AS CHARACTER .

DEFINE TEMP-TABLE ttERP_PODetailShort
FIELD PONbr AS CHARACTER
FIELD POLine AS INTEGER
FIELD ItemNbr AS CHARACTER
FIELD QtyOrdered AS DECIMAL .
/* Private ProDataSet for the PO short return object */
DEFINE DATASET dsERP_SHORT FOR ttERP_POShort, ttERP_PODetailShort
DATA-RELATION FOR ttERP_POShort, ttERP_PODetailShort
RELATION-FIELDS (ttERP_POShort.PONbr, ttERP_PODetailShort.PONbr) NESTED.

---------------Record create


IF AVAILABLE po_mstr THEN
DO:
FOR EACH pod_det WHERE pod_domain = po_domain
AND pod_nbr = po_nbr NO-LOCK BREAK BY pod_nbr.

IF FIRST-OF( pod_nbr ) THEN
DO:
CREATE /* tt */ ERP_POShort.
ASSIGN /* tt */ ERP_POShort.PONbr = po_mstr.po_nbr
Supplier = po_mstr.po_vend
Shipto = po_mstr.po_ship NO-ERROR.
END.

CREATE /* tt */ ERP_PODetailShort.
ASSIGN /* tt */ ERP_PODetailShort.PONbr = po_mstr.po_nbr
POLine = pod_line
ItemNbr = pod_part
QtyOrdered = pod_qty_ord NO-ERROR .
END.
END.

------------REST output
{
"response":
{
"dsERP_SHORT":
{
"dsERP_SHORT":
{
"ERP_POShort": [
 
{
"PONbr": "GG18558",
"Supplier": "VHKW0609",
"Shipto": "55"
}
],

"ERP_PODetailShort": [
{
"PONbr": "GG18558",
"POLine": 1,
"ItemNbr": "0457991N",
"QtyOrdered": 0
}],}}}}

---------------Write-json output
{"dsERP_SHORT":
{
  "ttERP_POShort": [
   
{
      "PONbr": "GG18023",
      "Supplier": "VHKH0706",
      "Shipto": "20020-G",
     
"ttERP_PODetailShort": [
       
{ "PONbr": "GG18023",
 "POLine": 1, "ItemNbr": "0457500D",
"QtyOrdered": 0.0
       
}  ]
    }
  ]
}}

All Replies

Posted by onnodehaan on 03-Jul-2017 01:05

Hi,

Perhaps you should to define a dataset.

And then use a data-relation to link the two table together.

If you use "write-json()" on the dataset, it will give you a nested JSON.

This thread is closed