Fascinating. I must test this approach.
However, it requires an extra control-value for each table - and those must be set to personal.
My clients may change that without realizing the importance.
This occurs when my clients add automations; those automations need control-values to be collaborative. So folks have changed this in the past withour realizing how it changes the behavours in other parts of the workflow.
Instead, I have used an alternative approach that does not require extra control-values but still avoids race conditions (among several users).
If you simply use Table1.Last() to select the row you just inserted, it will fail if another user has also just inserted a row. Each of you may or may-not get the correct row - the classic RACE condition.
So instead, we select the Last() row that was CreatedBy() this User().
However the formula to do that is
Table1.Filter(CreatedBy(CurrentValue)=User()).Last()
which can be very slow if Table1 has many rows (Filter() has to hit every row in the table).
So instead we first check that the Last() row was CreatedBy() this User(), if it was, then we use that and avoid having to run the Filter(). This is the most frequent case, and it runs very fast.
But if the Last() row was not CreatedBy() this User(), then we must do the whole Filter(CreatedBy(CurrentValue)=User()).Last() process. This is slower, but it avoids the race condition, and always gives us the correct row.
Here is an example where we create a new row in the PROJECTS table and then get a link to that row, called newProj, which we then use to create a row in the TASKS table for that Project.
RunActions(
PROJECTS.AddRow( // create new project
Name, "Test Project 1",
Owner, "max.xyzor@agile-dynamics.com"
),
If( PROJECTS.Last().CreatedBy() = User(), // no race-condition?
PROJECTS.Last(), // use last row in table
// otherwise we need to filter
PROJECTS.Filter(CreatedBy(CurrentValue)=User()).Last()
).WithName(newProject), // call the link "newProject"
TASKS.AddRow(
Task, "Initiate New Project", // add a new task
Project, newProject, // for this project
DueDate, Today()+7
)
)
Max