Hi Atlassians,
How to get DateTime CustomField Value of a specified issue?
My code is the following:
log.debug("get datetime customField Value: " + issue.getCustomFieldValue(customField_X).toString());
Did I miss something?
Thanks,
Rosy
looks nice. What is customField_X? how do you get that variable? Are you sure there is something inside that issue? can you get other custom field values using that code?
Hi Alexey,
I got that variable like this:
CustomField customField_X= customFieldManager.getCustomFieldObject(111);
where 111 is the ID of a Date/Time customField. I got the value of the custom field (Text Field) using that code.I should use a specific code for the DateTime field?
Thanks,
Rosy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I don't remember I've got some problem with getting of date fields. Could you please modify your code to
log.debug("get datetime customField class: " + issue.getCustomFieldValue(customField_X).getClass().toString());
and give the output generated? Do you see at least the message "get datetime customField Value: "
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Alexey, you are right, the output is: class java.sql.Timestamp. How should I convert it in order to get the value?
Many thanks,
Rosy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Timestamp stamp = new Timestamp(System.currentTimeMillis());
Date date = new Date(stamp.getTime());
System.out.println(date);
http://stackoverflow.com/questions/11839246/how-to-convert-timestamp-to-date-in-java
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
getCustomFieldValue(customField_X) is going to return the object that is in the field. For many types of object that get stored in fields, .toString() will give you something you can quite easily read and use.
But date and date/time fields return objects (Timestamps, if memory serves) which do NOT implement a .toString() that returns anything that's much use to a human.
You'll need to delve further into the object it does return to work out what you can use. Alexey's code will at least tell you the name of the class you need to work with!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As I remember it is Timestamp definitely. But I don't remember that it doesn't implement toString() method (I mean implements empty string) - as for the reference http://docs.oracle.com/javase/1.5.0/docs/api/java/sql/Timestamp.html#toString() implementation exists
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello again,
I used getValue instead of getCustomFieldValue(customField_X):
log.debug( "customField_X.getValue()" + customField_X.getValue(issue).toString());
and I obtained 2014-07-09 15:49:00.0 for example, now I will try to convert it into the format that I need , but at least, I got the value.
Thanks all,
Rosy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi all,
I sucessfully get the Date/Time Value of the CustomField using the following code:
public String getCustomFieldStringValue(Issue issue, CustomField customField) throws Exception {
String customFieldStringValue = "";
Object value = issue.getCustomFieldValue(customField);
if(value instanceof java.sql.Timestamp) {
DateFormat fullDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:SS");
DateFormat dateFormatWithoutSeconds = new SimpleDateFormat("yyyy-MM-dd HH:mm");
Date date = fullDateFormat.parse(customField.getValue(issue).toString());
customFieldStringValue = dateFormatWithoutSeconds.format(date);
}
log.debug("Custom Field " + customField.getName() + " has the following string value: " + customFieldStringValue);
return customFieldStringValue;
}
But, I'm still facing a problem with the Time Zone.
The value displayed is related to the Time Zone of the Server, however, I should obtain the value related to the Time Zone of the Client. For example, my server is in Paris and I'm using my plugin from Beirut = > The above code gives me the time related to Paris.
How to get the time depending of the time zone of the connected user, not the server where installed Jira?
Thanks,
Rosy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Rosy Salameh - perhaps this comes too late :-)
Have you tried:
def userTimeZoneValue = ComponentAccessor.getComponentOfType(TimeZoneManager.class).getLoggedInUserTimeZone().getProperties()['lastRule'].getProperties()['ID'].toString()
someDate.format('dd/MMM/yy HH:mm',TimeZone.getTimeZone(userTimeZoneValue))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.