Arrays - server side

Hi,

There’s something I struggle with Wappler - I don’t know how to push Objects into an array?

E.g.: The data coming from an API Action response

Imagine you do this API Action three times. How do you push everything into a single array? And how to define the schema of such array?

1 Like

You probably have seen this already but for others here is some documentation on Arrays that might help.

Hm… Interesting! It seems this is only for client-side stuff? (App Connect)

I can’t find this how to do this server-side, do you know if this is possible?

Array component and Data store is indeed for client side only.

Server side manipulation is usually combining different data sources. You can use data transformations for that:

How I push objects into arrays:

  1. Define the array with Set Value name = Data

  2. Inside a repeat: create an object with Set Value, and in my case:

{{{Name:mj_property_name,Value:mj_property_value}}}

(values come from the query I am putting in the repeat)

  1. Inside same repeat: push it to the array using `Data.push(obj)
    Now your data should be pushed into the array

Note: I am not sure if this formatter already exists in Wappler, but isn’t in the UI. I might’ve made it myself. Either case, if it doesn’t work you can add this custom formatter in extensions/server_connect/formatters/myformatters.js

  1. I’m not sure if I needed this: formatting the data as JSON
1 Like

As far as I understand, there’s no Wappler native way of doing array.push? Joining data sources doesn’t sound like doing an array.push :thinking:

I recommend adding Array support server-side, maybe something simple like adding Array formatters like Kars is doing above :point_up_2:

What currently exists:

Related feature request:

1 Like

Ditto.

The way serverconnect is setup is that each action step returns data that is defined by metadata so that Wappler knows the exact output. We don’t allow manipulation of the data, so when you have for example a push action you should return the new generated array in the push action step and not manipulate the result from the previous action.

For arrays this is not a really big deal since the data structure doesn’t really change, but for example adding properties or removing properties on an object will have influence. We currently don’t have a way in which we can describe with metadata how an action manipulates the result of a previous action.

For the array there will probably come a separate module which allows you do the same as on the client and more, I hope to post a beta version really soon.

:crossed_fingers:

1 Like