I need to have Incident End default to now as I close a ticket. Since I can't use Default value, I'm using a Jira Behaviour instead.
This script works EXCEPT the date/time is off by 12 hours when the timezone is not the same as the default time zone. If it's 5 PM in the US Central tz and 11 PM in the UK, the UK user closing a ticket has the Incident End set to 11 AM instead of 11 PM. It works correctly for a user in the US Central tz. What am I doing wrong?
@BaseScript FieldBehaviours fieldBehaviours
def dateField = getFieldByName("Incident End")
def timeZoneManager = ComponentAccessor.getComponent(TimeZoneManager)
def loggedUserZoneId = timeZoneManager.loggedInUserTimeZone.toZoneId()
DateFormat formatter = new SimpleDateFormat("dd/MMM/yy h:mm a")
def newLocalDateTime = LocalDateTime.now()
def newDate = Date.from(newLocalDateTime.atZone(loggedUserZoneId).toInstant())
dateField.setFormValue(formatter.format(newDate))
Hi @Maria DePasquale ,
Not sure if this will solve your issue, but this is the script I am using and it is working fine (it's very similar) :
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.timezone.TimeZoneManager
@BaseScript FieldBehaviours fieldBehaviours
def userTimeZone = ComponentAccessor.getComponent(TimeZoneManager).getLoggedInUserTimeZone()
SimpleDateFormat isoFormat = new SimpleDateFormat('dd/MM/yy HH:mm');
isoFormat.setTimeZone(userTimeZone);
def dateField = getFieldByName("Incident End")
dateField.setFormValue(isoFormat.format(new Date()))
Antoine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.