Set key attribute date default as "today"

(Bill Anderson) #1

Quick question:
I have a key attribute(date type) called PublicationDate.
The default is none, and creates an error elsewhere down the line on a web server.
I would like to set the default as “today”, however, every time I do, Tinderbox parses this to the actual date and time that I type the word “today” in the inspector.

How can I set a default that populates the key attribute as the current date and time on a note’s creation?
Thank you.

(Mark Anderson) #2

If I understand correctly, you want to set the doc-level default of a Date-type attribute to be the current date-time? I see the intent but I think you are really describing (only some?) notes’ $PublicationDate to be whatever was current at the time of export.

At present, although the default for any Date-type attribute is "never’ (i.e. undefined [sic]), other date designator values cannot be used as a default. Nor (which) I’ve tested can you use action code such as date("today") as a default. If you really want this, you may care to email support with a feature suggestion.

However, I think there is a simple solution as you state:

This is easily resolved in the export template. Lets assume it includes code such as ^value($PublicationDate)^ (or a formatted version thereof). Instead of:




At export, unless a note has a non-default value for $PublicationDate, it will instead insert the current date/time in default format. Of course, if you want a different format - e.g. locale short date only - then you’'d change:





(Bill Anderson) #3

Thank you for this code, Mark @mwra, I will explore this further.

Looking at this and other recent questions I’ve asked, I think my problem is that I have a persistent mental model that I must configure everything at the document level versus creating a contextual default for the specific task that I need to perform. Hmmm.

(Mark Anderson) #4

Sure, though in this case a doc-level default that is variable does seem a bit odd. If the default for $PublicationDate was ‘today’ then when I open the document tomorrow some notes’ $PublicationDate will have changed and it will also be more difficult to detect unset dates.

Another route, given that the problem you’re addressing is outside Tinderbox, might be to export your date like this:


That way, no value is written for export if $PublicationDate is not set (i.e. ‘never’).

(db) #5

Not sure if this helps, but I’ll try anyway. I have a journal with dated entries in Tinderbox. When I create the note, I want the default value of $EntryDate to be today. I accomplished this by adding an action to the container,


Whenever I create a note in the container, it sets the entry date to what I want.

(Bill Anderson) #6

Thank you, @drowsyfervour!