Hi, I am new to Coda and have been struggling with the following problem:
I have a table with various columns. I want a button that does the following:
When clicked it should add a row to the table and open it for editing. If the value of the column “Company” that is entered in the new row matches an existing row it should add the values of the other columns to the existing row with the same “Company”. If not, it should create a new row. Basically “Add or Modify Row”, as far as I understand it, but I have not been able to set this up.
Can anybody tell me how do achieve this?
Before pressing the button, you need to know the Company value the user wants to add-or-modify.
So for this example, i will assume that a textbox control called inputCompany exists where the user has entered the company they want to work on, and beside it is the button to either insert the company (if its new) or update and existing company by opening the row for editing. I am calling the table Companies in this example.
The formula for the button is as follows
Companies
.AddOrModifyRows(
Company=inputCompany,
Company, inputCompany
)
.OpenRow()
This will check if there is a row in Companies where the Company matches inputCompany
- if there is, it will modify the existing row and then open it for the user to edit
- otherwise it will insert a new row, set the Company column and open it for editing
You may want to reset the inputCompany text-box, in which case the button formula becomes…
Runactions(
Companies
.AddOrModifyRows(
Company=inputCompany,
Company, inputCompany
)
.OpenRow(),
inputCompany
.SetControlValue("")
)
You need to use RunActions() because you now have 2 actions to perform
Respect
Max
Thank you very much, Max. This is very helpful.
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.