Trying to set the value for a field based on another field so the value is retained as the original value.
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.CustomFieldManager
import java.sql.Timestamp
import org.joda.time.DateTime;
import org.apache.commons.lang.time.DateUtils;
import java.text.SimpleDateFormat;
import java.util.Date.*;
Issue issue = issue
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-YYYY");
def ocf = customFieldManager.getCustomFieldObjectByName("Expected Delivery Date")
def strDate = sdf.format(ocf).format("dd-MM-YYYY")
def cf = customFieldManager.getCustomFieldObjectByName("Original Delivery Date")
if (!cf)
issue.setCustomFieldValue(cf, strDate)
Error:
Time (on server): Wed Nov 09 2016 15:58:49 GMT-0600 (Central Standard Time)
The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.
2016-11-09 15:58:49,120 ERROR [customfield.GroovyCustomField]: ************************************************************************************* 2016-11-09 15:58:49,121 ERROR [customfield.GroovyCustomField]: Script field failed on issue: EXCHH-64789, field: Original Delivery Date java.lang.IllegalArgumentException: Cannot format given Object as a Date at java_text_Format$format.call(Unknown Source) at Script649.run(Script649.groovy:16)
If both custom fields are date type then you could use this code:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.CustomFieldManager CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager(); issue.setCustomFieldValue( customFieldManager.getCustomFieldObjectByName("Expected Delivery Date") , customFieldManager.getCustomFieldObjectByName("Original Delivery Date"))
If not, say types of these custom fields.
Both custom fields are date fields and I am trying to have a scripted field set the original date only when the expected date is entered the 1st time. If the expected date is changed we want the original to stay with what the 1st value was.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You should not use a script field to make any changes for the issue - it should only read information and display a calculated value.
You have different options here -
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Lets start with:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Looks like you are trying to set a Date CF to a String... set it to a Date. Vasiliy's code looks valid.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.