On How To Never Destroy Data

Iโ€™ve been contracted to rapidly develop an app for medical services. Part of the requirement is for me to ensure that data is never destroyed in order for the app to be certified.

This is commonly implemented in the following manner:

  1. Every table must include two columns: LifecycleStart and LifecycleEnd, each of type DateTime.
  2. On a โ€œCreate recordโ€ operation, set [LifecycleStart]=NOW(), and set [LifecycleEnd]=MAXDATE.
  3. On a โ€œDelete recordโ€ operation, set [LifecycleEnd]=NOW().
  4. On an โ€œUpdate recordโ€ operation, do the equivalent of โ€œDelete recordโ€ and then โ€œCreate recordโ€.
  5. Create a Slice with the following filter condition: AND(NOW() >= [LifecycleStart]), NOW() < [LifecycleEnd])

Conceptually it works for me. The only hurdle is how to override the default system-generated CRUD actions. Iโ€™ve read a few articles here at the forum that makes me believe that it is possible, but I must be doing something wrong.

Can anyone point me to a YouTube video that demonstrates how to do it? Absent that, any articles or posts that you would recommend?

Iโ€™m aware that I donโ€™t need to override the โ€œAddโ€ action. All I need to do is set these initial values: LifecycleStart=NOW() and LifecycleEnd=MAXDATE. So, I just need to override the โ€œEditโ€ and โ€œDeleteโ€ actions.

My rant:

I also planned for the possibility that Lifecycle management is beyond AppSheetโ€™s ability. Iโ€™ve made the client aware of possible shortcomings. They are onboard with contracting the development of a custom mobile app if AppSheet canโ€™t meet this requirement. At least they rapidly get to market with my app, and then use it to demonstrate to a software shop exactly what they want. That saves them a lot of money. The downside is that AppSheet loses paying customers when the custom app replaces mine.

Iโ€™m aware that I could log out data changes, but I donโ€™t fancy having to re-create the app state by rewinding the audit trail. I prefer to simply go to the Slice filter condition and replace NOW() with a specific date in the past.

Any feedback is greatly appreciated.

Thanks,
Brian

Solved Solved
0 7 236
1 ACCEPTED SOLUTION

Thanks Marc, your suggestion worked, but I had to be a little creative. I keep forgetting that the only state variables are those stored in columns. Youโ€™ll see my solution below:

First, I added a column called โ€œEdit IDโ€ in my โ€œActivityโ€ table. โ€œEdit IDโ€ is a placeholder for a new key that will be generated when I execute the โ€œLifecycle Create IDโ€ action.

Now, my reworked โ€œLifecycle Editโ€ action executes the following actions:
โ€œLifecycle Create IDโ€
โ€œLifecycle Deleteโ€.
โ€œLifecycle Create Copyโ€.
โ€œLifecycle Edit Copyโ€.

Here is what โ€œLifecycle Create IDโ€ does:
Data: set the values of some columns in this row
Set [Edit ID]=UNIQUEID() for this row.

Here is what โ€œLifecycle Deleteโ€ does:
Data: set the values of some columns in this row
Set [LifecycleEnd]=NOW()

Here is what โ€œLifecycle Create Copyโ€ does:
Data: add a new row to another table using values from this row
From/To table: Activity
Set ID=[Edit ID]
Set Activity name=[Activity name]
Set LifecycleStart=NOW()
Set LifecycleEnd=DATETIME(โ€œ12/31/2999 23:59:59โ€)

Here is what โ€œLifecycle Edit Copyโ€ does:
App: go to another view within the app
LINKTOROW([Edit ID],โ€œActivity_Formโ€)

Here is a screenshot demo:

View solution in original post

7 REPLIES 7

Hide the system-generated Delete and Edit Actions. Create your own Actions to replace them. Delete should be easy, just a data change. Edit should probably be a โ€œGroupedโ€ Action, with the same data change as Delete, then an โ€œAdd new rowโ€.


As for the second portion of your post, Iโ€™m afraid Iโ€™m not even sure what youโ€™re talking about.

Thanks for your reply, Marc. Sorry about that second portion of my post. I was just expressing frustration that I donโ€™t have greater control. โ€œNo Codeโ€ sounds great, but for a programmer it means โ€œHandcuffsโ€.

Iโ€™ve been experimenting prior to discovering your reply. I ended up doing exactly as you suggested by creating custom Actions. Everything works great except the final step in my Edit Action. Let me explain what Iโ€™m doing:

I created an Action called โ€œLifecycle Editโ€.
It executes a sequence of Actions:

  1. โ€œLifecycle Deleteโ€.
  2. โ€œCopy this row and edit the copyโ€.
  3. โ€œPromote Lifecycle to Currentโ€.

I created an Action called โ€œLifecycle Deleteโ€.
It sets [LifecycleEnd]=NOW() for this row.

I created an Action called โ€œCopy this row and edit the copyโ€.
It executes โ€œApp: copy this row and edit the copyโ€.

I created an Action called โ€œPromote Lifecycle to Currentโ€.
It sets [LifecycleStart]=NOW() for this row
and [LifecycleEnd]=DATETIME(โ€œ12/31/2999 23:59:59โ€)

When I click the โ€œLifecycle Editโ€ button on the current row, everything works except the last step โ€œPromote Lifecycle to Currentโ€. I was expecting that the โ€œcurrent rowโ€ would point to the copied record from the previous step. However, it appears as if the current row is undefined.

Do you know if this is expected behavior? Perhaps I should put in a ticket?

Thanks,
Brian

Hi @Brian_Morgan
I believe your sequence stops at the second action because this one involves a save and stops the process.
Added edit
You may need to use LINKTO FORM.

Thank you, Lynn, Iโ€™ll give that a try.
Brian

Sort of. It is because the โ€œcopy and editโ€ Action is a navigation Action.

This is why I suggested the โ€œAdd new rowโ€ Action, in which you can specify values for the fields in the new row. You may also wish to add a LINKTOROW() navigation as a 3rd Action in the group, if the record needs edited any further by the user.

Thanks Marc, your suggestion worked, but I had to be a little creative. I keep forgetting that the only state variables are those stored in columns. Youโ€™ll see my solution below:

First, I added a column called โ€œEdit IDโ€ in my โ€œActivityโ€ table. โ€œEdit IDโ€ is a placeholder for a new key that will be generated when I execute the โ€œLifecycle Create IDโ€ action.

Now, my reworked โ€œLifecycle Editโ€ action executes the following actions:
โ€œLifecycle Create IDโ€
โ€œLifecycle Deleteโ€.
โ€œLifecycle Create Copyโ€.
โ€œLifecycle Edit Copyโ€.

Here is what โ€œLifecycle Create IDโ€ does:
Data: set the values of some columns in this row
Set [Edit ID]=UNIQUEID() for this row.

Here is what โ€œLifecycle Deleteโ€ does:
Data: set the values of some columns in this row
Set [LifecycleEnd]=NOW()

Here is what โ€œLifecycle Create Copyโ€ does:
Data: add a new row to another table using values from this row
From/To table: Activity
Set ID=[Edit ID]
Set Activity name=[Activity name]
Set LifecycleStart=NOW()
Set LifecycleEnd=DATETIME(โ€œ12/31/2999 23:59:59โ€)

Here is what โ€œLifecycle Edit Copyโ€ does:
App: go to another view within the app
LINKTOROW([Edit ID],โ€œActivity_Formโ€)

Here is a screenshot demo:

Marc and Lynn,

Thank you very much for your help, but I just came up with a scenario that can only be solved by the AppSheet core since it is aware of the schema. For example, say I have two related tables: Parent and Child. Suppose I create a Parent record: โ€œCarolโ€. Carol has two children: โ€œAmandaโ€ and โ€œMelissaโ€. Now letโ€™s say that I misspelled the parentโ€™s name. It is really โ€œCarolaโ€. So I edit the parent record and Bam! The two child records point to the old retired โ€œCarolโ€ record. Not good.

Like I said I think this behavior is best handled by the AppSheet team. Perhaps they might want to offer it in a future version. In the meantime, Iโ€™ll revert to Plan B, writing to an Audit log.

Thanks again for your help. I send you โ€œLikesโ€!
Brian

Top Labels in this Space