Integration

Get Involved. Join the Conversation.

Topic

    Samuel Lima
    OIC - Cant map to list of items inside foreachAnswered
    Topic posted September 9, 2019 by Samuel LimaBlue Ribbon: 750+ Points, tagged Cloud, Integration, Mapping, Orchestration, PaaS 
    124 Views, 13 Comments
    Title:
    OIC - Cant map to list of items inside foreach
    Summary:
    In a integration orchestration, list of items becames one element list after for-each
    Content:

    Hi,

    How can I map the current element of a Foreach to each item of a list of items that must be returned by the Endpoint of the current integration?

    I have a list of elements returned by a REST Endpoin before the ForEach but after the loop ForEach it returns only one element in the list.

    I perform a calculation of business days between two dates calling a JavaScript Function that returns the duration in days.

    The result of the JS function should be updated in a specific field of each element of the list, but after ForEach the list becomes a one only element.

    Attached are the iar and jpg files.

    Thanks,
    Samuel

    Version:
    OIC Version: 19.3.2.0.0 (190819.0200.30840)
    Image:
    Document:
    Map.png (97KB)

    Best Comment

    Hemanth Lakkaraju

    The problem seems to be the way you are writing the csv file. The sample provided tells you have first line as Header and the same is used in read as well. But when you append the data while writing with 2 lines, the csv doesn't have the header, so I assume read is considering first line as header and showing only last line. Can you verify this with rest response having items > 2. I expect you to see last 2 lines in the response.

    How to fix this?

    Make sure you write CSV headers first before the for-loop and then use the same file within for-loop to write the data. Or re-model the stage write/read to use csv sample without headers and your problem should be solved.

    Comment

     

    • Monish Munot

      2 ways,

      1. Else edit the xslt outside to add the index i.e. counter created while creating for loop and map to the current element set, however in the screenshot it does not show correct target in the mappings.
      2. You need to write the content again using for loop where you will map all the elements again from your source to target and make use of current JS output to calculate field. In screenshot it shows you cannot map all elements or repeat and that's the reason it shows only one element.
    • Samuel Lima

      Hi Monish,

      I've made some corrections but no success and attached a Description.docx comparing the integration without map in For Each to the integration with Map in For Each.

      As I said, before Foreach Map is returned correctly but if I user a map inside foreach it returns a one element list.

      I thought of creating a counter and map to the list using its index position but didn't find it in the map in OCI.

      Could you please take a look at the description and tell me if there is an alternative for it?

      Thanks,

      Samuel

       

      • Hemanth Lakkaraju

        The flow is working fine as expected and with map within for-each. The map will get recreated everytime within the for-each loop.

        There is no direct way to perform a response aggregation.

        What you need to do to solve your problem?

        Create/Write a csv file with each Item data and the assign value using Stage Action.

        Read the file back using Stage Action.

        Map the response XSLT with Stage Read response using XSLT for-each.

      • Monish Munot

        Document helps a lot to understand the flow. In the "Map inside Foreach" activity target should not be repeatable element list, instead it should be your current index data. I believe if we fix this you are good to go.

        • Samuel Lima

          Hi Monish,

          I did it as you said and I've gotten some improvement.

          But now, the integration is returning only the last element of a list.

          After debugging each tracing payload I figured it out that the ForEach is working correctly.

          I mapped the current ForEach element to Write Stage component in each iteration.

          Write component is setup to append but the Read Stage reads only the last element written to file.

          It seems that append setup is not working in the Read Stage.

          Any clues on that?

          Thanks

          Samuel

          • Monish Munot

            Can you share the logs please with tracing enabled? I reviewed the integration and looks good, logs would help to analyze further.

    • Samuel Lima

      Hi, Hemanth,

      I gave it a try and got an "UnMappedFault" error.

      I user a Stage File inside For Each to write each item with append.

      After the ForEach, I user a Stage File to read the file.

      Then I mapped the output of the Read Stage File to the output of the endpoint.

      Attached the application and image with the error.

      Could you please help with me with that?

      Thanks,

      Samuel

    • Samuel Lima

      Some screenshots to help.

    • Samuel Lima

      Hi Monish,

      I changed the fields type int he Stage and it worked, that is, at least it is returning a list.

      But now there is one item repeated in the list, the "processId": "180323" as below.

      {
          "items": [
              {
                  "title": "cadastroAAI",
                  "createdDate": "2019-09-09T14:20:26.000Z",
                  "updatedDate": "2019-09-09T14:20:26.000Z",
                  "processName": "Process",
                  "processId": "180323",
                  "expirationDate": "Fri Sep 06 2019 10:20:30 GMT-0000 (UTC)",
                  "isExpired": true
              },
              {
                  "title": "cadastroAAI",
                  "createdDate": "2019-09-09T14:19:46.000Z",
                  "updatedDate": "2019-09-09T14:19:46.000Z",
                  "processName": "Process",
                  "processId": "170463",
                  "expirationDate": "Fri Sep 06 2019 10:20:30 GMT-0000 (UTC)",
                  "isExpired": true
              },
              {
                  "title": "cadastroAAI",
                  "createdDate": "2019-09-09T14:20:26.000Z",
                  "updatedDate": "2019-09-09T14:20:26.000Z",
                  "processName": "Process",
                  "processId": "180323",
                  "expirationDate": "Fri Sep 06 2019 10:20:30 GMT-0000 (UTC)",
                  "isExpired": true
              }
          ]
      }

       

      • Hemanth Lakkaraju

        The response depends on your actual response from REST invoke. Are there repeating processIds in the original response? because, what you are doing is the enriching the actual response from REST Invoke by modifying the expirationDate value.

         

        You may want to enable tracing for the integration and provide the diagnostics logs to see the issue if you can't figure this out.

        • Samuel Lima

          Hi Hemanth,

          I did some improvements in the integrations as you said.

          After debugging thoroughly the tracing, now the ForeEach loop is working correctly. The REST invoke does not have repeated elements.

          The problem was that I was mapping the repeated elements from REST invoke to Write Stage component which made it write more than one element in each iteration.

          I correct it to map only the current ForEach element to Write Stage, so the ForEach loop is now working fine.

          The problem now is that although the Write Stage writes only one element each iteration, the REad Stage only reads the last element written to csv file.

          What intrigues me is that the Write Stage is setup to append.

          Any clue on that?

          Thank you,

          Samuel

          • Hemanth Lakkaraju

            The problem seems to be the way you are writing the csv file. The sample provided tells you have first line as Header and the same is used in read as well. But when you append the data while writing with 2 lines, the csv doesn't have the header, so I assume read is considering first line as header and showing only last line. Can you verify this with rest response having items > 2. I expect you to see last 2 lines in the response.

            How to fix this?

            Make sure you write CSV headers first before the for-loop and then use the same file within for-loop to write the data. Or re-model the stage write/read to use csv sample without headers and your problem should be solved.

            • Samuel Lima

              Hi Hemanth,

              I did exactly what you said and it worked !!

              I unticketed the "Use First Row as Column Headers" in both Write Stage and Read Stage and the Read Stage could read the two elements written in the ForEach loop.

              Thank you very much !

               

              {
                  "items": [
                      {
                          "title": "cadastroAAI",
                          "createdDate": "2019-09-10T14:20:04.000Z",
                          "updatedDate": "2019-09-10T14:20:04.000Z",
                          "processName": "Process",
                          "processId": "200028",
                          "expirationDate": "Fri Sep 06 2019 10:20:30 GMT-0000 (UTC)",
                          "isExpired": true
                      },
                      {
                          "title": "cadastroAAI",
                          "createdDate": "2019-09-10T14:20:52.000Z",
                          "updatedDate": "2019-09-10T14:20:52.000Z",
                          "processName": "Process",
                          "processId": "210036",
                          "expirationDate": "Fri Sep 06 2019 10:20:30 GMT-0000 (UTC)",
                          "isExpired": true
                      }
                  ]
              }