Urgent Help to catch REST input to temp-table - Forum - OpenEdge General - Progress Community

Urgent Help to catch REST input to temp-table

 Forum

Urgent Help to catch REST input to temp-table

  • Hi,

    I have the request in below JSON format and want to catch the response in temp-table within a dataset. 

    {
    "request": {
    "ProductCode": "MUHOT00001",
    "productName": "Hotel K+K",
    "CheckInDate": null,
    "Duration": 0,
    "Video": [
    "abc1.mp4",
    "abc2.mp4",
    "abc3.mp4",
    "abc4.mp4"
    ],
    "prop_pics": [{
    "ProductCode": "MUHOT00001",
    "Prop_Url": "001room_1.jpg",
    "Prop_Title": "delux room"
    }, {
    "ProductCode": "MUHOT00001",
    "Prop_Url": "001room_2.jpg",
    "Prop_Title": "delux room"
    }],
    "room_types": [{
    "name": "Deluxe Room",
    "boardtype": "Half board",
    "occupancy": "2",
    "points": "1300+10"
    }, {
    "name": "Apartment Room",
    "boardtype": "Full board",
    "occupancy": "6",
    "points": "1300+8"
    }, {
    "name": "Twin Room",
    "boardtype": "Half board",
    "occupancy": "4",
    "points": "1300+15"
    }, {
    "name": "Suite",
    "boardtype": "Full board",
    "occupancy": "2",
    "points": "1300+20"
    }]
    }
    }

    When I catch the above request in separate input parameters then the values of video and prop_pics are like:

    Video =  ["abc1.mp4","abc2.mp4","abc3.mp4","abc4.mp4"]

    prop_pics = 

    [{
    "ProductCode": "MUHOT00001",
    "Prop_Url": "001room_1.jpg",
    "Prop_Title": "delux room"
    }, {
    "ProductCode": "MUHOT00001",
    "Prop_Url": "001room_2.jpg",
    "Prop_Title": "delux room"
    }]

    But I need to get all the values of prop_pics object ( ProductCode, Prop_Url and Prop_Title). And I find no better way to read the values of prop_pics.

     So, Is it possible to map the request to a temp-table with in a dataset ?

  • Hello,

    There are some few ways that you could use to handle prop_pics (and room_types) as a temp-table or a dataset:

    - Change format of prop_pics to temp-table, use a temp-table parameter in method/procedure.

    - Change format of prop_pics to dataset, use a dataset parameter in method/procedure.

    - Keep current format and use prop_pics as a character variable and process the value as JSON using the JSON constructs in the ABL.

    - Keep current format and use prop_pics as a character variable and process the value as JSON by mapping the value to a temp-table.

    Do you have control on the format for the input? I am guessing that the answer is Yes since you are using "request" which is expected when mapping to individual parameters.

    The key is that the input to of the request should have the format that is expected for the parameter.

    In your JSON object, the props_pics parameter has the structure of an array of object, however, this does not match the expected format for an array.

    The expected parameter looks like the following:

    "prop_pics": <Structure representing a Temp-Table>

    Example (excerpt):

    "prop_pics": { "prop_pics": [{

    "ProductCode": "MUHOT00001",

    "Prop_Url": "001room_1.jpg",

    "Prop_Title": "delux room"

    }, {

    "ProductCode": "MUHOT00001",

    "Prop_Url": "001room_2.jpg",

    "Prop_Title": "delux room"

    }]

    }

    Please notice that "prop_pics" is listed twice. Once as the name of the parameter and a 2nd tieme indicating the name of the table in temp-table definition. For a dataset, the format is similar and you would also need an object property with the name of the dataset.

    The temp-table parameter would look like the following:

    DEFINE TEMP-TABLE prop_pics

       FIELD ProductCode AS CHARACTER

       FIELD Prop_Url AS CHARACTER

       FIELD Prop_Title AS CHARACTER.

    I hope this helps.

  • Hi Egarica,

    I would like to pass temp-table ttTableRecFields  and two more parameter RECID and LangID . Would below format work?

    Please suggest -

    "request": {

    "ttTableRecFields": {"ttTableRecFields": [{

    "table_name": "Lang_ACTIVITY_DESCRIPTION",

    "table_field": "ACTIVITY_DESCRIPTION",

    "field_type": "Text",

    "field_length": "4",

    "field_required": true,

    "data": "行政收费" ,

    }]

    },

    "RecID":1540,

    "LangID":1

    }

    Thanks,

    Krishna

  • Hi,

    I am using PDS-OE for mapping JSON with programs. Below is post JSON.

    {
     "request": {
      "ttTableRecFields": [{
       "table_name": "Lang_ACTIVITY_DESCRIPTION",
       "table_field": "ACTIVITY_DESCRIPTION",
       "field_type": "Text",
       "field_length": "4",
       "field_required": true,
       "data": "行政收费"
      }, {
       "table_name": "Lang_ACTIVITY_DESCRIPTION",
       "table_field": "ACTIVITY_DESCRIPTION1",
       "field_type": "Text",
       "field_length": "4",
       "field_required": true,
       "data": "行政收费"
      }],
      "RecID": 1540,
      "LangID": 1
     }
    }

    And here is how I am mapping the aforesaid JSON object in PDS-OE. 

    When I am running this mapping via war file, I am getting below error.

    {
      "_errors": [
        {
          "_errorMsg": "ERROR condition: An incomplete client request. (8020) (7211)",
          "_errorNum": 8020
        }
      ]
    }

    I am not able to understand that how the array in JSON we can map in PDS-OE.

    Please help.

    Thank you,

    Krishna Kumar

  • Sorry for reposting as previous post had not include the image.

    --------------------------------------------------------------------------

    Hi,

    I am using PDS-OE for mapping JSON with programs. Below is post JSON.

    {
     "request": {
      "ttTableRecFields": [{
       "table_name": "Lang_ACTIVITY_DESCRIPTION",
       "table_field": "ACTIVITY_DESCRIPTION",
       "field_type": "Text",
       "field_length": "4",
       "field_required": true,
       "data": "行政收费"
      }, {
       "table_name": "Lang_ACTIVITY_DESCRIPTION",
       "table_field": "ACTIVITY_DESCRIPTION1",
       "field_type": "Text",
       "field_length": "4",
       "field_required": true,
       "data": "行政收费"
      }],
      "RecID": 1540,
      "LangID": 1
     }
    }

    And here is how I am mapping the aforesaid JSON object in PDS-OE. 

    When I am running this mapping via war file, I am getting below error.

    {
      "_errors": [
        {
          "_errorMsg": "ERROR condition: An incomplete client request. (8020) (7211)",
          "_errorNum": 8020
        }
      ]
    }

    I am not able to understand that how the array in JSON we can map in PDS-OE.

    Please help.

    Thank you,

    Krishna Kumar

  • Hello,

    The error "An incomplete client request" happens because the format is not expected for the parameters. In particular, the structure of the temp-table.

    The explanation in my previous post also applies here.

    The JSON for the ttTableRecFields parameter should be an object instead of an array.

    "ttTableRecFields": <Structure representing a Temp-Table>

    The name "ttTableRecFields" will appear twice. Once as the name of the parameter and a 2nd time as the name of the temp-table.

    (A way to troubleshoot this and see the structure is by testing outputting the parameters.)

    Example:

    {

    "request": {

    "ttTableRecFields": {

    "ttTableRecFields": [{

    "table_name": "Lang_ACTIVITY_DESCRIPTION",

    "table_field": "ACTIVITY_DESCRIPTION",

    "field_type": "Text",

    "field_length": "4",

    "field_required": true,

    "data": "行政收费"

    }, {

    "table_name": "Lang_ACTIVITY_DESCRIPTION",

    "table_field": "ACTIVITY_DESCRIPTION1",

    "field_type": "Text",

    "field_length": "4",

    "field_required": true,

    "data": "行政收费"

    }]

    },

    "RecID": 1540,

    "LangID": 1

    }

    }

    Please try using a JSON object as the one above.

    I hope this helps.