Can not Copy Due date into Target End Field.

GS1337 September 23, 2019

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?

3 answers

1 accepted

0 votes
Answer accepted
Jan Benda September 29, 2023

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. 

Result value:
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. 

0 votes
fran garcia gomera
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 23, 2019

@GS1337 

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);
GS1337 September 24, 2019

This Script upadates a value and Saves it, it doesnt copy the value from one date field to another tho

Like Consulente Atlassian likes this
fran garcia gomera
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 24, 2019

yes, updates the value of a date field with the previous value of another date field, isn't that copying a value?

GS1337 September 24, 2019

Yes there is a "YourDateFild" where i can enter the source field, where can i enter the target field?

fran garcia gomera
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 24, 2019
ModifiedValue(issue.getCustomFieldValue(customField), issue.getDueDate())

target field: issue.getCustomFieldValue(customField)

source field: issue.getDueDate()  

GS1337 September 26, 2019

I allready found a solution but thx for your answer

Normann P_ Nielsen _Netic_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 16, 2020

So, what was the solution? Would be nice to actually hear

0 votes
Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 23, 2019

hey @GS1337,

can you share your copy field script here to have a look 

BR,

Leo

GS1337 September 23, 2019

I used the build in Script in Script Runner "Copie Value of Field so another Field"

Mugilan Sukumar October 25, 2021

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.

Suggest an answer

Log in or Sign up to answer