Forum Discussion
Hi @KTsnap,
There is multiple ways of adding an element to an array. Besides the .push() method, you can use array concatenation:
$value.concat([{"color":null,"default":false,"description":null,"isActive":null,"label":"Active","urls":null,"valueName":"Active"}])
OR
[...$value,{"color":null,"default":false,"description":null,"isActive":null,"label":"Active","urls":null,"valueName":"Active"}]
Regards,
Bojan
- KTsnap5 years agoNew Contributor III
HI Bojan,
But it can be dynamic depending on the number of inputs.
its unsure in every run , whether we need to add one element or more than one element to the existing value. How we can implement the same for dynamic values- bojanvelevski5 years agoValued Contributor
@KTsnap, Concatenating can be on multiple elements. In the square brackets, list the elements that need to be added to the original array. That’s basically joining 2 arrays (array1 which is original, array2 which is array of values that need to be added)
- KTsnap5 years agoNew Contributor III
Hi Bojan,
I tried the above syntax. But its giving only the value inside the array. I need those value along with the input (the way extend works)- bojanvelevski5 years agoValued Contributor
Hey @KTsnap ,
Here is the array before the expression:
and here is the array after the expression:
Re-check if you are doing something wrong. If you were referring to the complete payload, than make sure you check Pass Through in the Mapper.
- KTsnap5 years agoNew Contributor III
the expected Output is as follows: [ { "entity": { "attributes": { "type":"CustomField","url":"A" } "Metadata": { "valueSet": { "value": [ { "color":null,"default":false,"description":null,"isActive":null,"label":"None","urls":null,"valueName":"None" }, { "color":null,"default":false,"description":null,"isActive":null,"label":"Country","urls":null,"valueName":"Country" }, { "color":null,"default":false,"description":null,"isActive":null,"label":"Employee","urls":null,"valueName":"Employee" }, { "color":null,"default":false,"description":null,"isActive":null,"label":"Both","urls":null,"valueName":"Both" }, { "color":null,"default":false,"description":null,"isActive":null,"label":"Active","urls":null,"valueName":"Active" } ] }, }, }, } ]