Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,556,072
Community Members
 
Community Events
184
Community Groups

Jira Behaviors - copying date field and formatting issue

Jon Starbird
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jul 18, 2018

I have an Initialize script in a behavior where I am trying to copy a date field value to another date field value if the destination one is empty. 

The copying aspect works but I wanted to format the date and followed the info here:

https://community.atlassian.com/t5/Jira-questions/Copy-date-field-if-date-field-is-null/qaq-p/10671

but when it runs it keeps setting the destination value to current date/time instead of the value from the other field.

Here is my code:

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.datetime.DateTimeFormatterFactory
import com.atlassian.jira.datetime.DateTimeStyle

if (getDestinationStepName() == "Scheduled")
{
def rcDateField = getFieldByName("Requested completion date")
def rcDateValue = rcDateField.getValue()
def scDateField = getFieldByName("Scheduled completion date")
def scDateValue = scDateField.getValue()

def dateTimeFormatterFactory = ComponentAccessor.getComponentOfType(DateTimeFormatterFactory)
def formatter = dateTimeFormatterFactory.formatter().withStyle(DateTimeStyle.DATE_TIME_PICKER)
def formatteddate = formatter.format(rcDateValue)

if (!scDateValue)
{
scDateField.setFormValue(formatteddate)
}
}

 

I've commented out the IF at the end so it's not that value isn't getting set, the value of formatteddate just isn't the formatted value of rcDateValue and is instead the current date/time.

 

Thanks.

 

 

1 answer

1 accepted

1 vote
Answer accepted
Aidan Derossett _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jul 25, 2018 • edited

Hey Jon!

I've played around with this for a hot minute and think I know what the problem is. After logging out some values, it looks like the value returned from the first date field is being returned as null, regardless of whether or not it has been populated. Because of that, I assume that the null value is being defaulted to todays date by the formatter. However, to fix this problem, all you need to do is take that code out of your initializer script, and instead use it as a server-side script directly on the "Requested completion date" field. 

I've encountered this problem before, and have opened a bug for it in our backlog that you might want to watch and vote on: SRJIRA-2808.

Try out the workaround that I've recommended and see if that does the trick for you. Let me know how it goes! :D

Best,
Aidan

Jon Starbird
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jul 25, 2018

Aidan,

     thanks, I'll do that.

Jon Starbird
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jul 17, 2019

This doesn't work at all now, regardless of where the script resides.

Jon Starbird
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jul 17, 2019

Figured out the issue. If I set the Behavior to use the Service Desk mapping type, it doesn't work. If I change it to use regular Jira/Issue Types, it works.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events