Modifyrows - selecting the column value with SwitchIf formula?

I would like that the date and time is registered when a button was pressed, but I want it in different columns based on a dropdown list (select list column).

E.g. If in the select list (Status) the value is “Selected” I want that the date and time of the button press is displayed on the column called “Selection date”, if the status is “Confirmed” then I would like that the date and time when the button was pressed is displayed on the “Confirmation date” formula. etc.

I am trying to use SwitchIf formula inside the ModifyRows formula, but unfortunately with this I don’t get the column as a result but a date as a result and it gives an error to me.

Do you have any suggestion how to make it work?

I created this formula:
ModifyRows(thisRow,switchif(thisRow.Status=Selected,thisRow.[Selection date],thisRow.Status=Confirmed,thisRow.[Confirmation date],thisRow.Status=Completed,thisRow.[Completion date],Now()))

Thanks in advance!

Hi @Tamas_Mahner,

I didn’t take a look at your doc, just formatted your formula with some tabulations (it helps me read code more easily) and I think your mistake is that you left the Now() inside of the switchIf().

Instead of

ModifyRows(
  thisRow,
  switchif(
    thisRow.Status=Selected, thisRow.[Selection date],
    thisRow.Status=Confirmed, thisRow.[Confirmation date],
    thisRow.Status=Completed,  thisRow.[Completion date],
    Now()
  )
)

it should be

ModifyRows(
  thisRow,
  switchif(
    thisRow.Status=Selected, thisRow.[Selection date],
    thisRow.Status=Confirmed, thisRow.[Confirmation date],
    thisRow.Status=Completed,  thisRow.[Completion date]
  ),
  Now()
)

Hope this helps,

Pablo

1 Like

Hello Pablo!
Indeed that was a syntax mistake, but even after fixing it, the error message is still the same:

Yeah, the switchif() returns a date and not the whole column, that’s why it fails.

Try this instead:

Switch(
  thisRow.Status,
  Selected,thisRow.ModifyRows(thisRow.[Selection date],Now()),
  Confirmed,thisRow.ModifyRows(thisRow.[Confirmation date],Now()),
  Completed,thisRow.ModifyRows(thisRow.[Completion date],Now())
)
1 Like

Wooooooooow!!!
Thanks a lot! It even works with RunActions in the more complex formula!

You made my day, thanks a lot!

1 Like

The only thing that I have to be cautious is that in case I change the select list items, I will have to be aware to change it also in the Switch formula, value part. I cannot link it so it changes if I change in the select list.

Yep, coupled code sucks

This could be an intersting read for you

1 Like

The more I work with Coda the more things I discover wanting to have which is not yet available. :smiley:

1 Like

That should not be the case, as you can see in the screenshot below both the possible values for Status and the date columns are chips. That means that if you change the name of the options in your select list or change the name of the columns, then everything will be dynamically updated and you won’t need to change the formula. If you add new options or new columns, of course you need to update the formula.

Maybe the problem was that when copying my code snippet the select list values were pasted as strings, therefore they wouldn’t be dynamic anymore.

Just type = next to Status , start typing the value and press Tab, so that the chip for the value will be generated. Then you can cut/paste it to the right place in the formula.

Let me know if anything is not clear,

Pablo

1 Like

Dear Pablo,

Again thank you very much for your support! At the end I created a table instead of a select list and in this way I managed to create the “chips” instead of the strings. But it’s good to know it is possible with the select list too!

All working perfectly now!

1 Like

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