I have a Scripted field this will calculate the date, but i want to append the result into an another customfield.
Reason Scripted field is storing the date and time. i want to store only date
Amar,
I'm not sure what you are asking here. Could you please clarify?
If you could share the code you are using for the scripted field, perhaps we can help you store just the date and not the date and time?
Below code gives me result in date and time.
I want only date. I cant get the date as scripted field does not support only date result.
I gives date and time.
So i want to write the result into another date customfield
import com.atlassian.core.util.DateUtils import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.changehistory.ChangeHistoryManager def dateField = new Date() long numberField = (long) getCustomFieldValue("Duration to close") MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject(issue.id); ChangeHistoryManager changeHistoryManager = ComponentAccessor.getChangeHistoryManager(); if (numberField == null || numberField == 0 ) { def X = changeHistoryManager.getChangeItemsForField (issue, "status") for (item in X?.reverse()) { log.error("X = ${item.getToString()} .. ${item.created.format("d/MMM/yy")} ${item.created.getDateString()}"); log.error("X = ${item.created}"); def Y = item.created log.error (Y.format("d MMM yy")) return Y break; }} int number = numberField.intValue() if (dateField) { Date result = dateField; Date newDate = new Date(result.getTime()) int i = 0 ; while (i < number-1) { result = result + 1 newDate = new Date(result.getTime()) if (newDate[Calendar.DAY_OF_WEEK] == Calendar.SATURDAY || newDate[Calendar.DAY_OF_WEEK] == Calendar.SUNDAY) { number ++; } i ++; } return newDate } return
I don't think there's a way to make Script Runner see it as just a date - even if you set the time element to 0:0:0 (which is what JIRA does internally when storing date data in date/time fields), that is still going to come out as "midnight on <date>" when you look at the field.
I suspect your options are:
I think what you want to do is store a date and time but display only the date. Even the JIRA date custom field stores a date time IIRC, but the time is set to midnight, which you can do yourself if you want with with Date#clearTime().
A custom template that renders the date only could be:
#if ($value) $dateFieldFormat.format($value) #end
I forgot about custom output. Oops.
Hi Jamie, Thanks, But if i use above template, JIRA date query is not working
Hi Nic, Can you share the code to update a date customfield with the result
Hi Amar,
I have looked at you code and have been able to format the returned Date/Time string using Java Simple Date format so that the returned output now shows the Day of the week, Day , Month and Year.
My refactored code is below with the two lines that are changed being lines 39 & 41 where I specify the date format and apply it to the newDate variable.
import com.atlassian.core.util.DateUtils import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.changehistory.ChangeHistoryManager import java.text.SimpleDateFormat; def dateField = new Date() long numberField = (long) getCustomFieldValue("Duration to close") MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject(issue.id); ChangeHistoryManager changeHistoryManager = ComponentAccessor.getChangeHistoryManager(); if (numberField == null || numberField == 0 ) { def X = changeHistoryManager.getChangeItemsForField (issue, "status") for (item in X?.reverse()) { log.error("X = ${item.getToString()} .. ${item.created.format("d/MMM/yy")} ${item.created.getDateString()}"); log.error("X = ${item.created}"); def Y = item.created log.error (Y.format("d MMM yy")) return Y break; }} int number = numberField.intValue() if (dateField) { Date result = dateField; Date newDate = new Date(result.getTime()) int i = 0 ; while (i < number-1) { result = result + 1 newDate = new Date(result.getTime()) if (newDate[Calendar.DAY_OF_WEEK] == Calendar.SATURDAY || newDate[Calendar.DAY_OF_WEEK] == Calendar.SUNDAY) { number ++; } i ++; } // Specify the format that we want the date retuned in SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy") // Format the date that we want to return def formatNewDate = sdf.format(newDate) return formatNewDate } return
I hope this helps.
Kristian
how can i use setCustomFieldValue
Hi Kristian, Errorr!!!!!!!
What do you mean by setCustomFieldValue. I used the code as a scripted field called "Close Date" using a text field renderer.
Should be just: issue.setCustomFieldValue(myDateCf, new Timestamp(resultOfCalculation)) The resultOfCalculation should be a date and time containing the full date and time, but if you define the field as a plain date (no time), JIRA will only store the date
any imports needed??? as currently i am getting this error mListener] Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: <inline script> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script283.groovy: 3: unable to resolve class Timestamp @ line 3, column 18. def dateField = (Timestamp) getCustomFieldValue("Estimated End Date") ^ error
Hi Guys,
Any solution???????
It looks like you're new here. Sign in or register to get started.