Help with Action Button needed

I have this table called Usina, where I will be controlling the making of concrete to distribute to clients and their projects.

In this table, I have a reference cell to CLIENTE and a reference cell to Obras (Projects). Which I would like to be filtered by the Projects of that client.

As I don´t know how to filter Obras by Cliente in that table, I created a second widget with cards from the OBRAS table, which is already filtered by the clients field in the Usina table.

Now, the question is how to select one of the projects in the filtered Obra table and have it inserted in the Usina>Obra reference field.

I tried to do it using the ACTION BUTTON. And failed miserably after an afternoon trying.

“description”:“Copiar Obra” + $CLIENTE.Nome,
“actions”:[[“UpdateRecord”, “Obra_Empreendimento”, None, {“Obra”:Obra_Empreendimento.Nome_Obra}]]

There is this message my Dimitry in another topic
[“UpdateRecord”, “TableId”, rowId, {“Col1”: Value1, “Col2”: Value2, …}]

Is TableId the source table or the target table? Same question for rowId.

I would guess both are source table, as the target table of the action is the table where the action formula is written, with the rowId being the currently selected row.

Ok… now {“Col1”: Value1… what dos that means? Col1 is the name of the column in the target table? Value 1 being the value from the specific field of the source table?

following my logic above with this code
“description”:"Duplicate record " + $CLIENTE.Nome,
“actions”:[“UpdateRecord”, “Obra_Empreendimento”, $id, {“Usina.Obra”:}]

It gives me an attribute error, saying that to retrieve all values from a column I should use


I don´t want to retrieve all values from that column. I just want the currecntly select card from the Obra_Empreendimento.

Also, when will you guys allow copying the error messages to post in the forum?

Hi @RogerioPenna,

I think that Action Button isn’t a good approach. It was never a very helpful widget, but here, I think it lacks the information you need to make the update – as with other linked widgets, it can know which record is selected in one of the widgets – either in Usina or in Obras, but it doesn’t know both selections.

I think in Grist, a somewhat different approach can be found that works better, we just need to figure out what makes the most sense in your case.

Would you be able to share a screenshot of the view you are imagining (maybe with dummy data, so there is nothing sensitive), and explanation of the workflow – i.e. what information you’d plan to enter, in what order? And what should be linked?

Now, let me make a guess as to the issue. I am may be wrong here, in which case ignore this next part :slight_smile: I am guessing that the issue is that you have some records that are tied to a Client, and the difficulty is how to tie these records to one of the projects for that specific client. This is a situation where we don’t have a perfect solution for – you normally tie records using a Reference field, and use the dropdown in the Reference cell to set the project. But the dropdown lists all projects rather than only those for a particular client. There have been requests to allow filtering this dropdown, but there are no such filters available yet. There are some workarounds, however – e.g. we can show a list of available projects, and set one by copy-pasting a cell. We can also add some rules that prevent setting an incorrect project (one that belongs to a different client).

Remember, this bit may not be relevant if I didn’t understand correctly what the difficulty is.

You got it exactly right Dmitry.

Yeah, I knew it wasn´t possible to filter a list of references based on another list of references. Or at least, it was’st back in the 2022 topic I had found about it.

Which is why I went with the action button.

I made some very cool stuff with the action button. I had some ChatGPT help, and ChatGPT seems to be getting dumber with each passing week, but it helped me more there than now.

actions = []
existing_treinamentos_funcionarios = set(Func_x_Treinamento.lookupRecords(Treino=$id).Funcionario)
count = 0
for e in Funcionarios.all:
  if e not in existing_treinamentos_funcionarios and e.Selecao:
    actions.append(["AddRecord", "Func_x_Treinamento", None, {
      "Treino": $id,
      "Presenca": None
    actions.append(["UpdateRecord", "Funcionarios",, {"Selecao":False}])
    count += 1
if actions:
    return {
      "button": "Gerar {} Registros".format(count),
      "description": 'Gerar registros de Treinamento'.format(count, $Titulo),
      "actions": actions
    return {
      "button": "Zero Registros",
      "description": "Zero Registros",
      "actions": actions

in this app I made, I create a Training. in “Cadastro Treinamentos”

In this screenshot, we see the screen where I select a training, then it shows all employees assigned to that training. (it’s an n-n table called FUNC x TREINAMENTO

Notice in this screenshot there is noone assigned.

On the Funcionarios (Employees) widget, I filter by department, by function, and SELECT employees. Then I click the ACTION BUTTON and it generates on the FUNCxTREINAMENTO several new records where it selects the ID of the selected training, and each employee in the list.

The last widget is an HTML generated with data from the training and the list of selected employees, so I can print and have them sign it.
Check here after I clicked to generate the 3 records of those employees selected in the previous screenshot

notice the 3 records created at FUNCxTREINAMENTO, notice that in the Funcionarios table it automatically “unclicked the employees”, and the HTML doc now has the 3 names.

I used as a basis for that (and for ChatGPT) one template you guys had of classes and attendants.

Dmitry, I got it!

I used the trick used in that Students Grade example (and my own example above) to tell WHICH record to use. That is, SELECTING a record with a toggle box

Here is the code

# Get the selected Obra_Empreendimento record (assuming there's a 'selected' field in the table)
selected_obra = next((record for record in Obra_Empreendimento.all if record.selected), None)

# Check if there's a selected Obra_Empreendimento
if selected_obra is not None:
    # Update the 'Obra' field in the current Usina record with the selected Obra_Empreendimento's ID
    action = ["UpdateRecord", "Usina", $id, {"Obra":}]
    # If no Obra_Empreendimento is selected, no action will be performed
    action = None

# Return the action button details
return {
    "button": "Update Obra" if action else "No Obra_Empreendimento selected",
    "description": f'Update Obra field with selected Obra_Empreendimento "{selected_obra.Nome_Obra}"' if action else "Please select an Obra_Empreendimento to update",
    "actions": [action] if action else [],