Split array, when , use "," in assign message inside payload

I have a request that give me an array that can be 1 to N.

ex:. [{123}],{test} or it can be [{123,124,125}],{test} and depending on this value will give a response (search) to those IDs. I am trying to use replaceAll to substitute , with "," to create elements inside the array.

It is not working. My sample inside Assign Message is:

<Set>
  <Payload contentType="application/json" variablePrefix="@" variableSuffix="#"> 
    { 
      "ID": "[{replaceAll(@id#, ",", "\")}]",
      "test":"@teste#" }
  </Payload> 
</Set>

and the result is (from a request with 3 IDs - 123, 124, 125):

{
  "ID": "[{replaceAll(123, ",", "\")}]",
  "test":"teste"
}

It appears exactly the replaceAll expression. What am i doing wrong? Should i use javascript instead to change this array? How do i proceed?

0 2 717
2 REPLIES 2

The prefix and the suffix belong outside the function.

use either this:

<Set>
  <Payload contentType="application/json"> 
    { 
      "ID": "[{replaceAll(id,',','-')}]",
      "test":"{teste}" 
}
  </Payload> 
</Set>

or this:

<Set>
  <Payload contentType="application/json" variablePrefix="@" variableSuffix="#"> 
    { 
      "ID": "[@replaceAll(id,',','-')#]",
      "test":"@teste#" }
  </Payload> 
</Set>

That may get you what you want. Hard to say, because you didn't show what you actually expect to get out of that replaceAll.

(The example you gave showed... I don't know, maybe an example input. But you didn't show the example output.)

Actually i tried it and it returns me the same:

{ 
  "ID": "[{replaceAll(123,124,',','-')}]",
  "test":"teste"
}

Actually i didn't told the response that i want. I want to get the next response:

{
  "ID": "[{123},{124}]",
  "test":"teste"
}

Elements inside an array. It could be only one element in array or N elements, depending on the request. I am trying with those 2 (123, 124) for example and it keeps returning that described in Code 1.