[SOLVED] Automatically close the last task when creating a new one

I have an app for task Management where you can log tasks, start time, end time, comments, status, etc. I want to add a Bot that automatically closes the last “In progress” task (meaning, endTime is blank) when a new one is created.

Here is a simplified version of the app: TaskManager - AppSheet

So far I have only been able to create an Action “End Task” that works and I’m trying to make another one “End Last Task” that will close the last created one. I’m having 2 difficulties:

  1. The bot doesn’t seem to run when a new task is created
  2. I can’t figure out how to select only the last created task (suppose in this case that are multiple users, so something like ([_THISROW].[_ROWNUBER] -1) doesn’t work).
Solved Solved
0 6 283
1 ACCEPTED SOLUTION

I personally do not like to use _RowNumber. I feel there is no guarantee that the rows will be in a known order - especially if the data comes from a database where a db view or indexing has modified the order.

This is what I would do.

In your use case you have just created a new Task row and want to “complete” the previous one. If we can assume that all previous task rows for this User have already been completed then there should only be two rows where ISBLANK([endTime]).

Then there are two ways to differentiate those rows:

  1. [startTime] - one is less than the other.
  2. [id] - assuming this is the key, is obviously different.

So I would use an expression like this:

SELECT(Tasks[id], AND(USEREMAIL() = [_THISROW].[User],
                      ISBLANK([endTime]),
                      [id] <> [_THISROW].[id]))
                                 

View solution in original post

6 REPLIES 6