I want to update the date of DAT TIME custom field-
String newTransferDate = formatDate.format(Calendar.getInstance().getTime());//must be of this format yyyy-mm-dd hh:mm:ss
//update the IPCompliance Transfer Time custom field.
Object newValue = null;
newValue = (Object) newTransferDate
I use the following API to update the "DATE TIME" custom field
Object customFieldOldValue = exportedCheckCustomField.getValue(currentIssue);
ModifiedValue modifiedValue = new ModifiedValue(customFieldOldValue, newValue);
FieldLayoutItem customFieldLayoutItem = ComponentManager.getInstance().getFieldLayoutManager().getFieldLayout(currentIssue)
.getFieldLayoutItem(exportedCheckCustomField);
exportedCheckCustomField.updateValue(customFieldLayoutItem, currentMutableIssue, modifiedValue, new DefaultIssueChangeHolder());
The updateValue method throws the below exception-
----------------------------------------------------------------------------------------------------------------------------------
class com.atlassian.jira.issue.customfields.impl.DateTimeCFType passed an invalid value of type: class java.lang.String
dLocalContainer] java.lang.ClassCastException: class com.atlassian.jira.issue.customfields.impl.DateTimeCFType passed an invalid value of type: class java.lang.String
dLocalContainer] at com.atlassian.jira.issue.customfields.impl.AbstractCustomFieldType.assertObjectImplementsType(AbstractCustomFieldType.java:111)
dLocalContainer] at com.atlassian.jira.issue.customfields.impl.DateTimeCFType.getStringFromSingularObject(DateTimeCFType.java:56)
dLocalContainer] at com.atlassian.jira.issu
Hi, use Timestamp, no string value.
Example:
CustomFieldType customFieldType = customField.getCustomFieldType();
Object oldValue = issue.getCustomFieldValue(customField);
Object newValue = null;
if (customFieldType instanceof DateTimeCFType) {
if (value != null) {
SimpleDateFormat sdf = getDateTimeFormat();
try {
Date date = sdf.parse(value);
if (date != null) {
newValue = new Timestamp(date.getTime());
}
}
catch (ParseException e) {
// Try Date and add zero time part
sdf = getDateFormat();
try {
Date date = sdf.parse(value);
if (date != null) {
newValue = new Timestamp(date.getTime());
}
} catch (ParseException ee) {
log.error("Wrong date time format exception for value [" + value + "], can not be assigned to Date Time field [id=" + customField.getId()+ ", name=" + customField.getName() + "].");
return;
}
}
}
}
issue.setCustomFieldValue(customField, newValue);
if (!dummy) {
// Update history for existing, no dummy issues
customField.updateValue(
fieldLayoutItem,
issue,
new ModifiedValue(oldValue, newValue),
changeHolder
);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.