Help with ForEach() and Modify Row

Hello again!

I’m having an issue with the ForEach formula. I swear I’ve done something like this before, but I guess not. I know there are other ways to get the list, but for this project I need it to be a button that does this.

Basically, I have two tables: PODS & SPECIALTIES:

SPECIALTIES Table:

PODS Table:

The tables have a relation with each other (they’ve been talking about moving in together, actually). My goal is to have a button on the PODS table that takes the Number values from each SPECIALTIES object and makes it into a list in the Specialty Numbers column on the PODS table.

Desired outcome after pressing button:
image

Button Formula:

However, when the button is pressed, it only puts the last value into the Specialty Number column:

I’ve tried to change around the formula multiple times but I can’t seem to get it to work. Could anyone explain why this isn’t working as intended?

1 Like

Hi Samuel,

I think you are overcomplicating it a bit. You can just use a formula without a button thisRow.[Pod Specialties].Number

If you really need a button you can use this formula then
thisRow.ModifyRows(thisRow.[Specialty Number],thisRow.[Pod Specialties].Number)

Hope this helps,

Pablo

2 Likes

Thanks for your response.

I know there are way easier ways to achieve this, but it’s just one part of a larger formula. In theory this should work, so I’m more looking for why it isn’t working rather than just a way to get the list of numbers, if that makes sense.

1 Like

So what’s the issue actually? That the Speciality Number field might already contain another number and you don’t want to overwrite it?

1 Like

:wave: @Samuel_Langford

with your button formula, because it’s used ForEach(), it overwrites the A (4) and B (5) one and thats why you’re left with C (6).
if you want all the numbers i.e. 4, 5, 6 then as @Pablo_DV has suggested, is to get the list combined and then just “stamp” (modify) the Specialty Number column once.

hope this helps!
Cheers!
Mel

1 Like

REPOSTING THIS BECAUSE I ACCIDENDLY DELETED THIS RESPONSE

It’s kind of a lot to explain, and I can’t share the doc. But basically:

There is a third table called PEOPLE, each row there has a has a column that ranks their specialty interests (1st, 2nd, 3rd). So I need a button to loop through the list of Specialty column values, look for a student that has that interest as their first choice, and then stick them into a column called People.

So something like this:

But it’s only giving me the last value, instead of 3.

1 Like

But if I’m using list combine, shouldn’t it stick the first value into the column, then the 2nd, then the 3rd?

1 Like

Theoretically I think your formula should work, but maybe the result of the previous modifyrows() has not yet been stored in the database when you are already calling the next one.

I would recommend to do the listcombine() within the formula and then store the value with a single ModifyRows(). Something like this

thisRow.ModifyRows(
  thisRow.[Specialty Number],
  ListCombine(
    thisRow.[Specialty Number],
    thisRow.[Pod Specialties].Number
  )
)
2 Likes

Amazing.

I got it working. Thanks so much!

1 Like

@Samuel_Langford

what @Pablo_DV said below is correct.
i didnt explain it right/properly… its got to do with race conditions (how coda processes order of execution).

i tried a ._Delay() formula for you but it still just comes up with 6.

one of those coda quirks :woman_shrugging:

4 Likes

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