Hi, all.
I’ve implemented a new DateTime field/column in a database collection. How do I get it be automatically filled in with the date and time when a new record is added to the database collection?
I have it started but want to know how to finish it; in the …_afterInsert() method, I have the following code:
let hookContext = context;
item.datetime = ?
Thanks
Or do I call the update( ) method?
Dates are already added on create and update. In the data collection take a look at the available visible columns. Normally these are hidden.
Thanks stcroppe. It seems like I have to make Created Date and Updated Date visible every time I want to check the Live database. Is that par for the course or is there a way to keep them permanently visible?
You can check them in code without making them visible. Visibility is only used in the dashboard view of the data collection. Simply access the properties using the keys _createdDate and _updatedDate.
So
dataItem._createdDate
dataItem._updatedDate
or
dataItem['_createdDate'];
dataItem['_updatedDate'];
@stcroppe Would this work with adding the time and date to a custom time and date field?
Yes of course. You would need to use the related date and time fieldKey.