Hi,
we have a Due Date Field in our Epics and Stories. People would like to work in the Portfolio and the Roadmaps there are only shown if u select a target start and target end. I created a function in Scriptrunner that copies the Date of the "Due Date" Field into the "Target End" Field. It works but it allways copies the date with -1. SO the Date is never correct. when i enter 30. as Due Date it copies 29. into Target End. Can anybody help me with this?
Hi, I found your issue but didn't find the answer yet, so I try to suggest mine.
From what I observed, the Target end Date value is internally stored including the timezone offset - my current timezone is CEST (UTC+2). Note that I am using the JMWE Groovy Console for testing (using a Groovy template that includes the script below enclosed in <% %>):
// Test script - attempting to store Due date value into Target end causes timezone issue
def p(Object o, String name) { println name + " (" + o.class + "): " + o.toString() }
// Values before update
p(issue.get("duedate"), "Due date")
p(issue.get("Target end"), "Target end original")
p(issue.get("Target end").timezoneOffset, "Target end.timezoneOffset")
// Update v1 - with timezone issue
issue.setFieldValue("Target end", issue.get("duedate"))
p(issue.get("Target end"), "Target end updated v1")
// Update v2 - adjusting for timezone issue
def java.sql.Timestamp upd = issue.get("duedate") // Due date (Date)
p(upd, "Date value required")
upd.clearTime().setMinutes(-issue.get("Target end").timezoneOffset) // add negative "Target end".timezoneOffset to required TS value
p(upd, "Date value adjusted")
issue.setFieldValue("Target end", upd)
p(issue.get("Target end"), "Target end updated v2")
See the outcomes of my test script below.
Due date (class java.sql.Timestamp): 2023-10-01 00:00:00.0 Target end original (class java.util.Date): Mon Oct 02 02:00:00 CEST 2023 Target end.timezoneOffset (class java.lang.Integer): -120 Target end updated v1 (class java.sql.Timestamp): 2023-10-01 00:00:00.0 Date value required (class java.sql.Timestamp): 2023-10-01 00:00:00.0 Date value adjusted (class java.sql.Timestamp): 2023-10-01 02:00:00.0 Target end updated v2 (class java.sql.Timestamp): 2023-10-01 02:00:00.0
I have observed that the "v2" update remediates the -1 offset issue in the Target end date.
Try something like this:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.issue.index.IssueIndexManager
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
def indexManager = ComponentAccessor.getComponent(IssueIndexManager)
def issueService = ComponentAccessor.issueService
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def issue = ComponentAccessor.issueManager.getIssueByCurrentKey('PT-1858')
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObjectByName('yourDateField');
customField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField), issue.getDueDate()),new DefaultIssueChangeHolder()); // update values
boolean wasIndexing = ImportUtils.isIndexIssues();
ImportUtils.setIndexIssues(true);
indexManager.reIndex(ComponentAccessor.issueManager.getIssueObject(issue.id));
ImportUtils.setIndexIssues(wasIndexing);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yes, updates the value of a date field with the previous value of another date field, isn't that copying a value?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
ModifiedValue(issue.getCustomFieldValue(customField), issue.getDueDate())
target field: issue.getCustomFieldValue(customField)
source field: issue.getDueDate()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So, what was the solution? Would be nice to actually hear
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.
Hi @GS1337
I tried to copy using same "Copie value of field" inbuilt script using script runner, but still the copied value is target date but its one day behind the actual date.
We are expecting you reply soon.
Thanks in advance.
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.