Skip to main content
Participant
August 9, 2023
Question

Auto-populate a field with the date it was created as mmddyy-XX.

  • August 9, 2023
  • 1 reply
  • 300 views

Hello,

I am trying to auto-populate a text field with the format being mmddyy-XX. The date is when it was created and XX being the number of forms created that day. I used the custom script:

 

this.addScript("init", "var f = this.getField(\"FORM#\"); if (f.value==\"\") f.value = new Date();");

 

to calculate and changed the format to date -> custom, and entered mmddyy. I am trying to figure out how to automize the XX portion so that it starts from 01 to however many forms were created that day. 


Thanks in advance and feel free to ask me more questions about this

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
August 9, 2023

First of all, you can't use the Date format for that. You need to set the Format to None and apply the formatted value directly to the field, using util.printd, for example.

The more tricky part is keeping track of how many forms you created during that day. I don't see a way to do that automatically, unless you can embed a script in each one of the forms that increments the value of a global variable, but then you would need to keep track of that file's name and creation data... A more simple solution is to add a menu or toolbar button that increments the value of this global variable and just click it each time you create a new file. Then you use that variable's value in the code that populates the text field, along with the date.