Legacy Dev Forum Posts

 View Only

Sign Up

Help to split a string and insert it into an array object DataAction output

  • 1.  Help to split a string and insert it into an array object DataAction output

    Posted 06-05-2025 18:45

    matheusscharf | 2024-02-14 23:19:54 UTC | #1

    Try to get a string "a;b;c;d" inside of datatables and return it on a array using dataaction.

    "successTemplate": "#set($Lista-array = $listaTab.replace(\"$esc.quote\", \"\").split(\";\")) {\n \"listaTabulacao\": \"$Lista-array\"}"

    { "listaTabulacao": "[ATIVO, EMAIL, FARMER]" }

    Error message: { "message": "JSON failed output schema validation for the following reasons: instance type (object) does not match any allowed primitive type (allowed: [\"array\"])", "code": "invalid.schema", "status": 400, "messageParams": {}, "contextId": "d9b871b7-e2ac-453a-b986-1213807910cb", "details": [ { "errorCode": "ACTION.PROCESSING" } ], "errors": [] }

    Output Contract Object-> Array -> String

    Any ideias?


    matheusscharf | 2024-02-15 00:14:39 UTC | #2

    Tried Object->Array->Object too:

    { "listaTabulacao": "{[ATIVO, EMAIL, FARMER]}" }

    { "message": "JSON failed output schema validation for the following reasons: Schema: # @/properties/listaTabulacao. Error location: /listaTabulacao. instance type (string) does not match any allowed primitive type (allowed: [\"array\"])", "code": "invalid.schema", "status": 400, "messageParams": {}, "contextId": "90946f4c-9621-4750-b5a3-bafabd45cdac", "details": [ { "errorCode": "ACTION.PROCESSING" } ], "errors": [] }


    Jason_Mathison | 2024-02-15 02:20:33 UTC | #3

    Returning an array of strings should look something like

    {
        "listaTabulacao": ["ATIVO", "EMAIL", "FARMER"]
    }

    So on your first example instead of doing a split, replace ; with ", " Meaning something like:

    "successTemplate": "#set($Lista-array = $listaTab.replace(";", "$esc.quote, $esc.quote:")) {\n "listaTabulacao": [\"$Lista-array\"]}" I didn't check if that was exactly right, but hopefully gets you in the right direction.


    matheusscharf | 2024-02-15 13:25:45 UTC | #4

    Hi Jason! Thank you for your post, but it didn't work

    We are no able to remove this first quote... Still appearing as a String.

    { "listaTabulacao": [ "ATIVO,EMAIL,FARMER" ] }


    Jason_Mathison | 2024-02-15 14:59:00 UTC | #5

    The issue may be that you are doing a split on ";" (semicolon), but the strings are actually separated by "," or comma.

    --Jason


    matheusscharf | 2024-02-15 18:01:57 UTC | #6

    I already tried with "," and still having the same issue unhapply


    Jason_Mathison | 2024-02-15 18:33:31 UTC | #7

    Please provide the output that you are getting from the endpoint (Shows up as the "Execute" step in test mode) and an export of your action to look at.

    --Jason


    matheusscharf | 2024-02-16 12:04:55 UTC | #8

    { "listaTabulacao": "ATIVO,EMAIL,FARMER", "key": "COMERCIAL" }

    Get-Data-Table-Row---v3-2024021690244.custom.json|attachment (1.4 KB)


    Jason_Mathison | 2024-02-17 19:18:11 UTC | #9

    This seemed to work for me

    {
          "translationMap": {
            "listaTab": "$.listaTabulacao"
          },
          "translationMapDefaults": {},
          "successTemplate": "#set($Lista-array = $listaTab.replace(\",\",\"$esc.quote, $esc.quote\")) {\n \"listaTabulacao\":[$Lista-array]}"
    }

    matheusscharf | 2024-02-17 22:50:10 UTC | #10

    Wow! It worked here. Thank you a lot @Jason_Mathison !


    system | 2024-03-19 22:50:33 UTC | #11

    This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.


    This post was migrated from the old Developer Forum.

    ref: 24653