How to handle temp-tables with id as a fieldname over JSDO?
 
Forums / SmartComponent Library - Developer Forum / How to handle temp-tables with id as a fieldname over JSDO?

How to handle temp-tables with id as a fieldname over JSDO?

5 posts, 1 answered
  1. Patrik Wikström
    Patrik Wikström avatar
    68 posts
    Registered:
    15 Oct 2018
    Answered
    22 Mar 2019
    Link to this post
    We have created a Data Access class that uses REST to get and send data.
    The tables in the data all have id as the unique keyfield for the records. We tried to add the id-field as id2 in the temp-table as used SERIALIZE-NAME = "id", First it looked like it would work but when we are fetching the Catalog over JSDO is says:
    {
        "title": "A runtime error has occurred",
        "error": "Progress.Json.JsonError",
        "messages": [
            {
                "message": "Call to Progress.Json.ObjectModel.JsonObject:Add( ) failed. Attempted to add duplicate property 'id'. (16056)",
                "messageNum": 16056
            },
            {
                "message": "Error attempting to push run time parameters onto the stack. (984)",
                "messageNum": 984
            },
            {
                "message": "Error attempting to push run time parameters onto the stack. (984)",
                "messageNum": 984
            },
            {
                "message": "Error attempting to push run time parameters onto the stack. (984)",
                "messageNum": 984
            }
        ]
    }

    Is there a way to solve this and why is "id" chosen as the new for a generated fieldname?

  2. Mike Fechner
    Mike Fechner avatar
    319 posts
    Registered:
    14 Sep 2016
    22 Mar 2019 in reply to Patrik Wikström
    Link to this post
    "id" is a standard field/column name used by the JSDO.

    Simplest solution is, to rename the field in the Business Entity. There is no need to change the Database field name.
  3. Patrik Wikström
    Patrik Wikström avatar
    68 posts
    Registered:
    15 Oct 2018
    22 Mar 2019 in reply to Mike Fechner
    Link to this post
    Yeah, that is what we did but the fetching the Catalog doesn't work after that (see above). The fetching of the data works.
    The field in the Business Entity is named "id2" and has SerializeName set to "id".
    Last modified on 22 Mar 2019 09:03 by Patrik Wikström
  4. Mike Fechner
    Mike Fechner avatar
    319 posts
    Registered:
    14 Sep 2016
    22 Mar 2019 in reply to Patrik Wikström
    Link to this post
    "Doesn't work after that" does not allow to provide any meaningful feedback.

    Using "id" as the serialize-name is however not the way I'd solve this. You'd still end up with two times "id" in the resulting JSON. Sounds like a recipe for failure to me. 
  5. Patrik Wikström
    Patrik Wikström avatar
    68 posts
    Registered:
    15 Oct 2018
    22 Mar 2019 in reply to Mike Fechner
    Link to this post
    Somehow there is only "id" once in the JSON (fetched through the JSDO) but you're right when we think about it! Thanks for the eye-opener!

    The data from the REST-service is ProDataSet compatible after we add the temp-table name and dataset name to the JSON fetched. Then we just use READ-JSON on the prodataset to get the data but there is no good place for easy mapping of the fields (Business entity id2-field and REST service JSON-data which has the id-field)? Perhaps we just loop through the JSON-DATA and add a id2 field to it with the value of the JSDON data id-field before reading it to the dataset...

    Thanks!

    EDIT:

    Solved(?) it by temporary setting the SERIALIZE-NAME on the prodataset buffer when reading the JSON-data.
    Last modified on 22 Mar 2019 10:03 by Patrik Wikström
5 posts, 1 answered