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.
Hi @alfresco1576,
Aren't you just assigning myDate to be today?
Hi,
Where you are writing above code?
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.
I am writing the code inside JavaScript in the form.
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; }
Ask for and offer help to other Alfresco Process Services and Activiti Users and members of the Alfresco team.
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.