How to update createdAt and updatedAt fields in your data type?

Hi, 

For best practice I have added a createdAt and updatedAt field in my CDT. This is generally good to have on several of my CDTs to trace activity in the future.

How do I save a date/time to these fields with system generated data at the time of form submission? What are the recommended solutions for something like this? 

Many thanks, 

Eric

  Discussion posts and replies are publicly visible

Parents
  • Something else you could also do is, instead of having createAt / updatedAt in your CDT, you can have the underlying database table written to have a CREATED_DATETIME / UPDATED_DATETIME field and in your database table schema specify the CREATED_DATETIME column to have a DEFAULT value of CURRENT_TIMESTAMP and the UPDATED_DATETIME column to have an ON UPDATE value of CURRENT_TIMESTAMP.

    The nice thing about this is you no longer have to enforce providing values for these fields at the application level, so if a new developer wants to write to these tables, they don't have to remember to fill in these values before writing to the table.
Reply
  • Something else you could also do is, instead of having createAt / updatedAt in your CDT, you can have the underlying database table written to have a CREATED_DATETIME / UPDATED_DATETIME field and in your database table schema specify the CREATED_DATETIME column to have a DEFAULT value of CURRENT_TIMESTAMP and the UPDATED_DATETIME column to have an ON UPDATE value of CURRENT_TIMESTAMP.

    The nice thing about this is you no longer have to enforce providing values for these fields at the application level, so if a new developer wants to write to these tables, they don't have to remember to fill in these values before writing to the table.
Children
No Data