Automation Pushing Button isn't the same as Manually Pushing Button

I have a button that generates a random row value based on the size of a table:

ModifyRows(row, row.value, RoundUp(Product(table.Count(), Random()), 0))

When I push the button it works perfectly and updates the value.

However, if I set an automation to have that formula action, it fails. I thought maybe disintermediating with a button would work, so I created a button that has this action, and set an automation to push the button. It fails too - and by saying it fails I mean the automation runs, but it always results in the same value. When I manually push the button, it generates a proper random value and updates. Ideas why it only works manually?

Hi @Johg_Ananda,
I remember something very similar and I think it might be related .
Please, have a look at here:

The current Random() implementation leaves out this edge conditions.

Let me know if this is relevant as I’m curious.

I’m testing this is it looks to be working fine. I don’t know your full setup, but when you say it generates the same number, is it setting the same number for a full column or is it generating the same random number every time?

@BenLee thank you for graciously helping. The formula works, I know. It doesn’t seem to work when incorporated into an automation. I am having some trouble debugging because in the automation history it shows the result of the ‘automation-run’ and it shows the ‘random’ value as X. When I go and look at prior ‘automation-runs’ it also shows the value as X. So I took this as meaning it was not changing the value. However I noticed now that no matter how far back I go, the value always shows as X, despite it having been Y and Z and other numbers, so the automation history is not helping. I know what the value is now and have set an alarm to check again in two hours when it runs. It doesn’t appear to have been working but now I need to double check.

Can you see if you can get your formula to work in an automation to reset a cell/row value to be the random output?

It’s working clicking the automations test button, but not sure about when the automation runs on it’s own. Doing the same thing and waiting to see what happens here too.

1 Like

Okay, the automation fired and the number changed for me from 1 to 3. So it’s working on my setup. I have a canvas button with the following formula that is editing a full column, but it should work if you have column buttons too…

ModifyRows(
  [My Table], [My Table].[Column], 
  RoundUp(Product([My Table].Count(), Random()), 0)
)

Then the automation pushes this button.

1 Like

@BenLee thanks … I still can’t make it work. My button works by itself. The automation successfully ‘pushes’ the button but then it does two things that are unexpected.

1 - it does not ‘really’ push the button because the action does not fire
2 - It shows the same results in the Activity section, when I mouse over the results field from that step.

Interestingly, if I push the[ :arrow_forward:Test Rule ] button, it DOES take action and update properly. Here is a gif showing the situation:

What you are showing in the GIF, the “quote” hover, is actually reading from the current value and not the value that was written at that time. So on the next run, it might show a different number for all of those.

Instead, open a row in the table and where comments are, click on “Activity”. That should show what values were updated at what time.

As you can see it was returning the same value repeatedly (15, 15, 15).

When I read your prior post I added a third step to the automation, and then recorded the gif. You can see the third step in the gif the formula step which changes the cell directly. Perhaps that has fixed it? Here is the activity:

Automation Bot is indeed a different thing than doing an action manually (i.e. in the browser, not on the servers). Testing automation is NOT running it as an Automation Bot, but STILL as you. The only time automation indeed runs like it would is when it’s triggered on the server (row-changed, time-based, crossdoc sync etc).

I don’t know about the Random() function, but a bunch of time- and user-based functions (User(), Now(), Today()) aren’t guaranteed to calculate on the server side. That’s because Coda servers don’t normally evaluate docs, but only read from the last snapshot calculated and pushed into the storage by last viewer’s browser.

The implementation of Random() is usually based on time for pseudo-entropy, hence could also be affected. I.e., last timestamp in the doc is 1234567890 epoch milliseconds, and when used as seed for Random() calculation, it would always yield the same value. That’s my assumption about what’s happening.

Random should be working fine here. I think it depends on other things you have going one. Here’s a screenshot of the activity from my setup using that exact formula. The doc was closed and my computer was off overnight, so this was fully on the servers. Also, only 3 rows in the table so not a ton of variety, but the value was changing…

I think you probably have more loaded in with the automation and those are the places I’d look to troubleshoot.