Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
> Thanks, But if i use above template, JIRA date query is not working what indexer is in use?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
custom field -> edit -> searcher
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
> Thanks, But if i use above template, JIRA date query is not working How????? is it not working?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am using application called Eazybi to create the charts and if i change the template then i cannot do any operations to plot the chart. Simply the field dis appears from here
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It's really not the right thing to do, but you can use a listener to update another field. Do *not* do it from the script field code. It would be better to have EasyBI understand the formatting of a date.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
the code is as follows import com.atlassian.core.util.DateUtils def dateField = (Timestamp) getCustomFieldValue("Estimated End Date") log.error (dateField.format("d MMM yy"))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you don't need to include (Timestamp)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.getCustomFieldValue() is applicable for argument types: (java.lang.String) values: [Estimated End Date]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What do you mean by setCustomFieldValue. I used the code as a scripted field called "Close Date" using a text field renderer.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You would be best to use Jamies template above the for to make the Field a Date / Time picker field. Otherwise use a script listener which updates a date field based on the value of the Duration to close field.
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 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:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
the code is as follows import com.atlassian.core.util.DateUtils def dateField = (Timestamp) getCustomFieldValue("Estimated End Date") log.error (dateField.format("d MMM yy"))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Last error while doing
import com.atlassian.core.util.DateUtils import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.customfields.CustomFieldType import java.sql.Timestamp; com.atlassian.jira.issue.IssueImpl; MutableIssue myIssue = issue; def Y = getCustomFieldValue("Estimated End Date") log.error (Y.toTimestamp()) def X = (Y.toTimestamp()) issue.setCustomFieldValue("Close Date", X) log.error(X)
groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.IssueImpl.setCustomFieldValue() is applicable for argument types: (java.lang.String, java.sql.Timestamp) values: [Close Date, 2015-12-07 13:13:07.911]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That call expects you to pass it a custom field object, not a string. Try replacing that with a getCustomFieldByName call
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
same error groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.getCustomFieldByName() is applicable for argument types: (java.lang.String) values: [Close Date]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, you need a manager class in there - CustomFieldManager.getCustomFieldByName
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
groovy.lang.MissingMethodException: No signature of method: static com.atlassian.jira.issue.CustomFieldManager.getCustomFieldByName() is applicable for argument types: (java.lang.String) values: [Estimated End Date]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.
Register Now
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.