Genesys Cloud - Developer Community!

 View Only

Sign Up

  • 1.  Preserve indexes when using nested arrays in Data Actions

    Posted 5 days ago

    Hi everyone!

    I'm working with a Genesys Cloud Data Action that returns nested arrays, for example:

    {
      "companies": [
        {
          "document": "12345678000100",
          "accounts": [
            { "number": 10001 },
            { "number": 10002 }
          ]
        },
        {
          "document": "98765432000100",
          "accounts": [
            { "number": 20001 }
          ]
        }
      ]
    }

    I need to access the accounts dynamically while preserving their relationship with the parent company, e.g.:

    companies[0].accounts[0]
    companies[0].accounts[1]
    companies[1].accounts[0]

    However, when I expose the nested properties through the Data Action Output Contract/Translation Map, there are limitations.

    My workaround was to return the entire API response as a raw string and then convert it to JSON inside Architect, which preserves the original JSON structure.

    Has anyone found a way to configure the Output Contract + Translation Map so that companies[*].accounts[*] preserves the relationship between the parent and child indexes?

    Thanks!


    #DataActions

    ------------------------------
    Daniel Souza
    ------------------------------


  • 2.  RE: Preserve indexes when using nested arrays in Data Actions

    Posted 5 days ago

    Hi Daniel,

    From what I understand, the limitation here is specifically around flattening nested arrays for Architect. Genesys has confirmed previously that flattening does not support nested arrays, and Architect uses the flattened Data Action output.

    So preserving a structure such as:

    companies[n].accounts[m]

    through the normal flattened output becomes problematic.

    Your workaround of returning the raw JSON as a string and then using JsonParse() in Architect is actually an approach that has been discussed previously in the Genesys Developer Community. In that discussion, Jason Mathison from Genesys confirmed that this was how he would handle the scenario. (Genesys Community)

    Previous discussions:

    https://community.genesys.com/discussion/api-is-returning-data-but-architect-errors-out-when-trying-to-print-the-data

    https://community.genesys.com/discussion/data-action-returning-json-in-success-template

    Hopefully someone else from the Community who has handled a similar nested parent/child structure can add their experience or another approach as well.

    Hope this helps!



    ------------------------------
    Phaneendra
    Technical Solutions Consultant
    ------------------------------



  • 3.  RE: Preserve indexes when using nested arrays in Data Actions
    Best Answer

    Posted 5 days ago

    Hi Daniel!

    I had a similar situation with nested arrays in a Data Action.

    When I used wildcards in the translation map, such as companies[].document and companies[].accounts[*].number, the results were returned as separate flattened collections. Because of that, the relationship between the company index and its accounts was lost.

    In my case, I followed the same approach you mentioned: I returned the response as a raw string and parsed it as JSON inside Architect. This preserved the original structure and allowed me to access each company and its accounts using the correct indexes.

    Another option would be to change the response structure before it reaches Architect and return a flat array containing both values, for example:

    { "document": "12345678000100", "accountNumber": 10001 }

    This makes the relationship explicit, but it requires transforming the response in the source API or another integration layer.

    As far as I know, the Output Contract and Translation Map alone cannot reliably preserve the parent-child relationship when both levels use dynamic nested arrays. So, for this scenario, parsing the raw JSON or normalizing the response before returning it are the safest approaches.



    ------------------------------
    ---------------------
    Leticia Roque Oliveira
    Senior Full Stack Developer
    ---------------------
    ------------------------------