Hi,
There is “UX Status” dropdown custom field with below status values
- NA (default)
- Grooming Needed
- Ready for Design
- Ready for Development
- Ready for UX QA
There should be read-only field, to capture the Date when above Status is changed
- Grooming Needed Date (Date field)
- Ready for Design Date (Date field)
- Ready for Development Date (Date field)
- Ready for UX QA Date (Date field)
I have written behavior script on "UX status" field. I am trying to only set a custom field to the current date/time (timestamp) if it is currently empty (null). If there is already a value set, no action should occur.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.APKeys
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import groovy.transform.BaseScript
import java.time.LocalDateTime
import java.time.LocalTime
import java.time.format.DateTimeFormatter
@BaseScript FieldBehaviours fieldBehaviours
def singleSelect = getFieldByName('UX Status')
def singleSelectValue = singleSelect.value
def groomingNeededDateField = getFieldByName('Grooming Needed Date')
def readyForDesignDateField = getFieldByName('Ready for Design Date')
def readyForDevelopmentDateField = getFieldByName('Ready for Development Date')
def readyForUXQADateField = getFieldByName('Ready for UX QA Date')
//Set the appropriate date value, dependent on the value of the currently selected single select option
switch (singleSelectValue) {
// Change 'Single Select Option...' to match your single select's values.
case 'Grooming Needed':
if(groomingNeededDateField ==null){
setValueToDateField(groomingNeededDateField)
}
break
}
void setValueToDateField( FormField groomingNeededDateField) {
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def dateFormatText = ComponentAccessor.applicationProperties.getDefaultBackedString(APKeys.JIRA_DATE_PICKER_JAVA_FORMAT)
def jiraFormatter = ComponentAccessor.getComponent(com.atlassian.jira.datetime.DateTimeFormatter).forUser(currentUser)
def dateFieldFormat = DateTimeFormatter.ofPattern(dateFormatText, jiraFormatter.locale)
def newLocalDateTime = LocalDateTime.now().with(LocalTime.MIN)
groomingNeededDateField.setFormValue(dateFieldFormat.format(newLocalDateTime))
}
As of now I'm trying on groomingNeededDateField but it's not working properly. why so?