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.
×Hi there,
We are currently using ScriptRunner to send auto emails as post-functions. In our email template we are using a date/time custom field (Responses Due By) and the Due date field to communicate required info to our distro groups.
In order to keep the custom Responses Due By field the same as the Due Date field, I'm working on adding another custom scriptpost-function using ScriptRunner to copy the Responses Due By field over to the Due Date field. For some reason it is giving me a 'no failures' but it does not actually copy the custom field over to the Due Date field. I'm hoping that someone can look at my code and tell me what I'm doing incorrectly.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueInputParameters
def mutableIssue = issue as MutableIssue
def issueService = ComponentAccessor.issueService
def customFieldManager = ComponentAccessor.customFieldManager
def issueManager = ComponentAccessor.issueManager
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def responsesDueBy = customFieldManager.getCustomFieldObjectsByName('Responses Due By').first()
def responseValue = issue.getCustomFieldValue(responsesDueBy)
def issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.setDueDate(responseValue.toString())
issueManager.updateIssue(loggedInUser, mutableIssue, EventDispatchOption.DO_NOT_DISPATCH, false)
If you are executing this in a post function, it's quite possible that the issue object that exists in memory during the transition overwrites your changes.
Normally, within a post function, I use the built-in issue object. As long as the sequence has this post function before the "update change history for an issue and store the issue in the database" built-in function, the issue object that you've modified will be included in the storeing and indexing
Here is what your code for doing that would look like:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import java.sql.Timestamp
def customFieldManager = ComponentAccessor.customFieldManager
def responsesDueBy = customFieldManager.getCustomFieldObjectsByName('Responses Due By').first()
def responseValue = issue.getCustomFieldValue(responsesDueBy) as Timestamp
(issue as MutableIssue).setDueDate(responseValue )
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Lara Arthur and @PD Sheehan
Does this script bring over both the time and date to the system due date field? We are currently looking for a while to "add" a time to the system due date field instead of it always having 'mid-night' as the set time.
Thanks,
mike
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If the source custom field is a Date Time picker, then the system date field will also contain the time after copying the data from the source custom field to the system date field.
But if the source custom field is a Date Picker, it is by convention stored with a time of midnight and will be copied as such. You can't invent precision that's not stored in the db.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi again @PD Sheehan
I've tried to implement your code above for my Responses Due By "date time picker" customfield as below:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import java.sql.Timestamp
def customFieldManager = ComponentAccessor.customFieldManager
def responsesDueBy = customFieldManager.getCustomFieldObjectsByName('Responses Due By').first()
def responseValue = issue.getCustomFieldValue(responsesDueBy) as Timestamp
(issue as MutableIssue).setDueDate(responseValue )
But when the postfunction runs, it doesn't seem to be pushing over the "time" aspect of the field into the default / Jira system field "Due Date".
For example:
Responses Due By = 1/1/2024 @ 5:00pm
Due Date = 1/1/2024
Resolution Date = 1/1/2024 @ 4:34pm
I've tested this push over via the search for issues page with ScriptRunner's issueFunction & compareDate JQL.
Ex: project = my_project AND issuetype = "Data Request" AND issueFunction in dateCompare("", "resolutionDate > dueDate")
If I run the above, even though the Resolution Date within the request is less than (earlier) than the Due Date, it still shows up within the issue search.
Is there any reason you can think of as to why it wouldn't be pulling over the time into the Jira default / system Due Date field?
Thanks,
Mike
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Actually… I don’t think I thought my earlier response all the way through.
The system due date field is a date picker only field if I recall correctly. So it would not be able to display the time even if it was stored in the db.
So the api will just ignore the time portion and store midnight.
I don’t think that there is any way around that.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi again @PD Sheehan
Thanks for the quick reply. It's really sad if we can't record a time for the system / default due date field.
We use that field for all issues, and the users at our company are requiring the ability to be able to "work" on issue during the due date. I realize we could port all of our current due dates over to a customfield, but I was hoping we wouldn't have to update 100s if not 1000s of filters, dashboards, and issues.
Thanks again for all the help!
Mike
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.