Simple array variable -> array of objects

I have a “newLabels” array variable that I use to store the uuids of selected items from a multi-select element.

Since this reflects a many-to-many relationship in my database (Supabase), I’m now trying to use this array as part of a batch insert on a junction table i.e. I want to insert as many records as there are items in the array, each with key1 : (same value for all records) and key2: (array item value).

I know the binding syntax for this to work needs to be an array of objects but I can’t figure out how to turn my simple array variable into an array of objects where key 1 has the same value for all items and key 2 has the value of the corresponding item in the array variable.

The AI formula helper is not helpful, only producing formulas that don’t work.

I think this is basically the same question as in this thread Create multiple objects from multi-select except I would like a no-code solution. The last reply in that thread indicates that should be possible but doesn’t elaborate on how.

Any help would be appreciated, thanks!

Hi @gduteaud :wave:

The only idea that comes to mind right now is to use a for loop action in a workflow through the array and create a new one with the proper formatting.

Does that help?

1 Like

Thank you Joyce! That makes sense but it turns out what I wanted to do is trivial to implement in JS so that’s what I did.

3 Likes

Nice! Would you mind sharing the solution for others who may read this in the future?

1 Like

Hi @gduteaud,

I’m facing a similar challenge right now. I’d appreciate if you could share?

I’m trying to use the formulas provided by WeWeb, but none of them seem to apply.

Figured it out!

I didn’t know you could write JavaScript into the formula field!

Here’s what I put into the formula field:

"MultiselectCurrentSelection".map(function(val){ return {"key1":  globalContext.pageParameters['variable'], "key2": val};})

The shortcut syntax would be use a fat arrow val => ... instead of function(val){...}, but the formula editor gets in the way.

1 Like

Yeah my solution was also to use JS. FYI on the top left of the formula editor you can change it to an actual JS editor, that should solve your arrow function issue!

1 Like

WOW! Thanks @gduteaud! I’m still learning the WeWeb interface. That’s amazing!

Pretty stoked that you can get into the code if you need to. Good job WeWeb!

1 Like