Skip to Content
0
May 27 at 02:13 PM

SAP CAI - storing json array using script

154 Views

Hello,

I have the following challenge:

I have a JSON file stored in the memory with the name "API_result". The stucture looks something like this:

"memory": {
      "API_result": [
        {
          "value A": "aaaaa",
          "componentId": "000000000019981475",
          "value B": "bbbbb",
          "value C": "CCCCC"
       }
        {
          "value A": "aaaaa",
          "componentId": "000000000003136619",
          "value B": "bbbbb",
          "value C": "CCCCC"
        }

       {
          "value A": "aaaaa",
          "componentId": "000000000003121415",
          "value B": "bbbbb",
          "value C": "CCCCC"
        }
        ]
}

I want to store the values of component ID in a separate memory (memory.instrument) as JSON, something like this:

"memory": {
      "instrument": [
        {
          "c_Id": "000000000019981475",
       }
        {
          "c_Id": "000000000003136619",
        }

       {
          "c_Id": "000000000003121415",
        }
        ]
}

To do this, I used the action "update memory" -> "set memory" with the option "Use scripting to build my JSON" enabled. I use following code (based on the documentation)

{{#eachJoin memory.API_result}}
    {  
      "c_ID": {{componentId}}
    }
  {{/eachJoin}}

This code causes a warning and those not store anything in memory.instrument.

 {
        "level": "warning",
        "code": "W_EXECUTE_ACTION",
        "data": {
          "type": "edit_memory",
          "value": {
            "invalid_json": "    {\r\n      \r\n      \"c_ID\": 000000000019981475\r\n      \r\n    }\r\n,    {\r\n      \r\n      \"c_ID\": 000000000003136619\r\n      \r\n    }\r\n,    {\r\n      \r\n      \"c_ID\": 000000000003121415\r\n      \r\n    }\r\n,    
            "scripting_enabled": true
          },
          "message": "No valid JSON value for field instrument"

I tried some other variations but had no luck. Any hint is highly welcome.