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

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?

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": []
}

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.

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"
]
}

image

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

--Jason

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

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

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

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

This seemed to work for me

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

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

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