Why Splice adds strange elements to my list?

Dear Community,
I’m very new to Coda, but I can’t help programming all my ideas in my documents . :slight_smile:
All the issues I could solve by myself by watching tutorial videos & sample docs of other, but this one.

I have two tables. In the first ([Szintek], means Levels) I defined some groups for my users based on their knowledge (like Beginners, Advanced …).

[Szintek].
[Name]: That’s the name of the level
[Tanulók]: That’s a multiselect People type, which allows me to assign the users to the appropriate groups

The other table i have is [Hírek] (means News). Here I’d like to publish the latest news targeted to one or more user groups (defined in the [Szintek]) table before.

[Hírek].
[Cím]: Just the Title for the news.
[Szint]: Selection field linked with [Szintek].Name
[Hozzárendelve]: A multiselect People field which I’d like to get populated from the [Szintek].[Tanulók] where the [Szint] matches.

I have created a button in the [Szintek] Table with the following Action:

ModifyRows(
     [Hírek].Filter(Szint.contains(thisRow)),
     [Hírek].[Hozzárendelve],
     [Hírek].[Hozzárendelve].Splice(0,0,thisRow.[Tanulók]).ListCombine().Unique()
)

It should do the job, and it does when I press the button for the first row in [Szintek]. However, when I press the button on the second row (to have populated the other group of users to the [Hírek].[Hozzárendelve] fields, it doesn’t just add the users assigned to the second user group, but also adds other users which were populated as I pushed the button for the first time (for the first row).
I have no idea, why… Is it a bug or a feature :slight_smile:
Thanks for any advice, as I’m quite stuck …

Cheers,
Marci

Can you talk us through what the Splice() is intended to do?

Hi Nick,
Sure. Splice should add the users of the actual group to the “targeted users” [Hozzárendelve] of the [Hírek] (news) table. It is important, that it retains the users already there, as I click through the button of every rows in [Szintek] one after another to make sure, every assignement is refreshed in the [Hírek] table.

Hey @Marton_Posz
could you share your doc - or at least a copy showing this behaviour?
This would make easier to dig into it: thank you!

1 Like

Sure, here you are:

Thanks for sharing!

I think I got the reason.
You have this in your formula:

ModifyRows([Hírek].Filter(Szint.contains(thisRow)),
   [Hírek].[Hozzárendelve],
   [Hírek].[Hozzárendelve].Splice(1,0,thisRow.[Tanulók]).ListCombine().Unique())

However, in this case you are updating multiple rows at a time. Meaning that the value you are referring to [Hírek].[Hozzárendelve].Splice() is the combination of all the filtered rows.

In order to make it work, you need a reference to each row instance every time. You can achieve this by expliciting an iteration over the filtered rows:

[Hírek].Filter(Szint.contains(thisRow)).FormulaMap(CurrentValue.WithName(row, 
    row.ModifyRows(
        [Hozzárendelve], 
        row.[Hozzárendelve] //here row.[Hozzárendelve] is actually referring to each row every time and not the full set.
           .Splice(1,0,thisRow.[Tanulók]).ListCombine().Unique()    
          )
    ))

I hope this helps.
Cheers!

7 Likes

Hi Federico,

You’re awesome! Exactly that was the point I was missing. I watch the tutorial with Formulamap, but was not sure I can make use of it in this situation.
Thanks again, I will remember this solution for my rest of my life.

Cheers,
Marci :smiley:

3 Likes

Happy it worked, @Marton_Posz! :slight_smile:

If you mark it as “Solution”, it will help others when searching for similar topics.
Thank you!

1 Like

A was looking for the “Solution” button, but so far I haven’t found it. As soon as I manage it, I will mark it…
:sweat_smile:

1 Like

Here we go! :wink:

Untitled
Untitled 2

image

You have magic buttons. I have just heart. :slight_smile:

1 Like

No worries @Marton_Posz :wink: , I’ve done it for you :blush: (as it might be a limitation due to the fact that you’ve joined recently :thinking: )

4 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.