How to display current date in the form?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2020 10:25 AM
I want to display the current date in the form. So whenever you create new process instance, it should fetch the current date and display in the form.
Issue: I am able to get and display current date but that code is running everytime I open the form and display that date. (If I create new process instance today, today's date is displaying in the form but if I open form tomorrow then it will display tomorrow date)
How can I make sure that it should only display the date when the form is created for particular process instance?
Code to get current date:
var myDate = scope.findFormFieldWithId(scope.allFormFields, 'myDate');
var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0');
var yyyy = today.getFullYear();
today = mm + '/' + dd + '/' + yyyy;
myDate.value = today;
Then I am using "Display text" form field to display 'myDate'
Thanks in advance.
- Labels:
-
Alfresco Process Services
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-20-2020 09:55 AM
Hi @alfresco1576,
Aren't you just assigning myDate to be today?
Problem solved? Click Accept as Solution!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2020 10:18 AM
Hi @EddieMay
new Date() will store current date into variable "today".
And I am assigning it to field called "myDate".
I need to make sure new Date() should not run everytime I open the form and store new date into variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-24-2020 12:14 AM
Hi,
Where you are writing above code?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-18-2020 10:20 AM
I am writing the code inside JavaScript in the form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-19-2020 12:01 AM
In your code, place condition and check that your field has a value or not and base on that write your code.
var myDate = scope.findFormFieldWithId(scope.allFormFields, 'myDate'); if(myDate.value==null){ var today = new Date(); var dd = String(today.getDate()).padStart(2, '0'); var mm = String(today.getMonth() + 1).padStart(2, '0'); var yyyy = today.getFullYear(); today = mm + '/' + dd + '/' + yyyy; myDate.value = today; }
