I'm trying to fill in a date field via automation (smartvalue). The issue is created from another system via webhook, and I can't change the date format. How can I have jira parse an arbitrary date format, eg how can I provide the format string to parse the string into a date?
You will have to play with the string and date smart value functions.
String smart values: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/
Date smart values: https://support.atlassian.com/cloud-automation/docs/jira-smart-values-date-and-time/
Regards
I don't see how that would work. The string functions are just things like substring, there is nothing like java.time.LocalDate.parse()
The second link only lets your format a date object in various ways, not generate one from a string (at least not that I can see).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Seth Hettich -- Welcome to the Atlassian Community!
Yes, and...to what Fabian suggests:
Once you get your date into a string/text format, try using toDate to convert it.
Kind regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I can't seem to get it into a string fomat that toDate will accept, eg:
"{{issue.description.match("Created Time: (\d\d/\d\d/\d\d\d\d) \d\d:\d\d:\d\d [+]\d\d\d\d").replaceAll("(\d\d)/(\d\d)(\d\d\d\d)", "$2-$1-$3")}}"
generates a string the whole date (with slashes)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am unclear what that source format is you are getting, and I recommend starting with just the date in Jira Date format, yyyy-mm-dd, and write the source and the parsed values to the log as you confirm it. Once that works, try adding the time information.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The input comes in the description from an external system, so I can't change it.
The format is:
MM/DD/YYYY HH:MM:SS +Z
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for that information. I recommend parsing out the text version of the date/time as you have done and storing that in a created variable. Then try the toDate conversion on that.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The issue is that call to replaceAll produces a string of the format "MM/DD/YYYY"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In that case, please take your replaceAll result, and save that in a created variable,
Then use other text functions such as substring() to pull that apart and put it into the jiraDate format yyyy-mm-dd, and
Then try the conversion with toDate.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Bill Sheboy How are you supposed to know about .toDate? That’s a string function, but I don’t see it at https://support.atlassian.com/cloud-automation/docs/jira-smart-values-text-fields/ or https://support.atlassian.com/cloud-automation/docs/jira-smart-values-date-and-time/ .
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Nathan Phillip Brink -- Welcome to the Atlassian Community!
Short answer:
For me it was experimentation and repeatedly reading the docs. That toDate function can be found here: https://support.atlassian.com/cloud-automation/docs/examples-of-using-smart-values-with-dates/#Converting-text-to-dates
Longer answer:
The original Code Barrel blog had lots of info, but that is gone now that the product was acquired by Atlassian. The current documentation has improved over time, but still has a challenge that many things are not where you would expect them to be, and some of the examples have typos.
Many of the very helpful things are quite well hidden in the examples sections, like these:
Plus there are links out to the "based upon..." tools, like regular expressions from Java Pattern class for the match() function. I recommend jumping out to those when you see them, and then creating a test rule to learn if A4J actually works that way. Spoiler: the regex appears to be different when used for match().
Kind regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.