Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Parse a datestring in a smartvalue

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?

1 answer

0 votes
Fabian Lim Community Leader Dec 06, 2021

Hi @Seth Hettich

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).

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

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)

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.

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

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.

The issue is that call to replaceAll produces a string of the format "MM/DD/YYYY"

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.

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you