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.

1 Like

:crossed_fingers:

2 Likes

@George @patrick any updates with server side arrays? Maybe there are some working workaround which can at least emulate arrays?

Workaround provided by @karh not working for me since I value can inserted with triple { }

@notum what are you trying to achieve exactly? I made some very simple server side formatters to add some missing things like pushing to an array.

I also use RunJS often for these things.

Perhaps I can share something

1 Like

I’m trying to find a workaround - how can I create similar to array functionality.
Looks like on second attempt I was able to achieve what I need.

image

image

Glad you got it working :smiley:

1 Like

That’s already possible using the Server Connect Array List component:

This topic was automatically closed after 26 hours. New replies are no longer allowed.