Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Updating "DATE TIME" custom field leads a error

SuhailM
Contributor
March 22, 2012

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

1 answer

1 accepted

0 votes
Answer accepted
Radek Kantor
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 22, 2012

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
	);
}

SuhailM
Contributor
March 22, 2012

Thanks al ot

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events