I am using forms and workflow. I need to save the form with a name using a date prefix yyyymmdd-. How can I convert a date field from the form to this format to be used as part of the document name?
Question
Question
date conversion
Replies
Hi John,
You just use an 'Assign Token Values' activity after the 'Retrieve Business Process Variables' one, referencing the token from your form like so (in this case mine was called 'Date Term Begins':
Check the 'Apply Formatting' box and put this inside: yyyyMMdd
You can then test the value, put an arbitrary date in the Text Value box and you will see the updated date at the bottom as the 'Result Value' as above. Now use a 'Rename Entry' activity to rename whichever entry you want, and insert the token into the name, i.e. 'Starting Form - %(formattedDate)' if your token is called 'formattedDate' as mine was.
Hi,
I think the easiest way to do that is though Token Dialogue..
Choose Token dialogue on the entry name where you want to rename your document..
Then select the date on which you want to format and
Check on Apply formatting and enter yyyymmdd then you are done.
Ok. I was hoping I could reformat a variable in the Forms process but it looks like I have to create a Workflow Service task to create a variable from a date field formatted as yyyyMMdd. Thank you for the answers.
In form you can accomplish it by using javascript with additional singleline field..
create a single line field to hold the formatted date which will be used for renaming your document.
add these scripts #q6 is the date which you want to format, and #q7 is the formatted date ready for renaming your document.
function formatDate(date) { var d = new Date(date), month = '' + (d.getMonth() + 1), day = '' + d.getDate(), year = d.getFullYear(); if (month.length < 2) month = '0' + month; if (day.length < 2) day = '0' + day; return [year, month, day].join(''); } $('#q6 input').on('change',function(){ $('#q7 input').val(formatDate($('#q6 input').val())).change(); });
choose the formatted field in the save to repo task
And here it is in the repository
I hope now you are fine
Very cool. I am going to keep the javascript for future reference because it is more elegant than what I ended up using to solve this. What I did was create 3 single line variables on my form for Year, Month, and Day. For each variable, I put the following expression in the advanced tab:
Variable Year: =YEAR(SubDate)
Variable Month: =IF(MONTH(SubDate)>9,MONTH(SubDate),CONCATENATE(0,MONTH(SubDate)))
Variable Day: =IF(DAY(SubDate)>9,DAY(SubDate),CONCATENATE(0,DAY(SubDate)))
SubDate is a date variable used on my form.
Under the Field Rules, I chose to Hide these fields since they were only used to name the saved form once the task was completed:
Field Rules "Hide" "Year" "Save data when the field/section/page is hidden" "Always"
Hi Emmanuel Fredy,
I used a Forms input date field in the JS code that is supplied here. Everything works fine except that the resulting date which is correctly formatted(yyyy-mm-dd) is one days less. If I select the 1st May 2023, the result is 2023-04-30.
The client is using Forms V 11.0.2106.
Any help will be appreciated much,
Thanks,
Sam