1 year ago

#199769

test-img

user1783675

Copy date from one field to another

I am trying to copy the value of one date field to another. But, the field is not getting set. When I hardcode the date value it works.

Original field is Scheduled Start Time and the field I am trying to copy the value to is: Planned Scheduled Start Time. These are both date type fields.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.properties.APKeys
import com.atlassian.jira.datetime.DateTimeFormatter as JiraDateTimeFormatter
import com.atlassian.jira.issue.customfields.impl.DateTimeCFType
import com.atlassian.jira.issue.fields.CustomField
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import java.time.LocalDate
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.temporal.TemporalAccessor
import java.time.format.DateTimeFormatter
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.user.util.UserUtil
import java.util.Date.*

@BaseScript FieldBehaviours fieldBehaviours

// The date & date time field names to set a value
final plannedScheduledStart = "Planned Scheduled Start Time"
final plannedScheduledCompletion = "Planned Scheduled Completion Time"

final scheduledStart = "Scheduled Start Time"
final scheduledCompletion = "Scheduled Completion Time"


// Get the components
def customFieldManager = ComponentAccessor.customFieldManager
def authenticationContext = ComponentAccessor.jiraAuthenticationContext

// Get the date & date time field objects
//def dateFieldStart = customFieldManager.getCustomFieldObjectsByName(plannedScheduledStart).first()
def dateFieldStart = getFieldByName("Planned Scheduled Start Time")
def dateFieldCompletion = customFieldManager.getCustomFieldObjectsByName(plannedScheduledCompletion).first()

def dateScheduledStart = customFieldManager.getCustomFieldObjectsByName(scheduledStart).first()
def dateScheduledCompletion = customFieldManager.getCustomFieldObjectsByName(scheduledCompletion).first()




def dataValue = dateFieldStart.getValue().toString()

getFieldByName("Scheduled Start Time").setFormValue(dataValue)

I also tried def dataValue = dateFieldStart.getValue() and it failed

groovy

jira

scriptrunner-for-jira

0 Answers

Your Answer

Accepted video resources