Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,644,756
Community Members
 
Community Events
196
Community Groups

Can not Copy Due date into Target End Field.

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
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
Sep 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.
Sep 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);

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.
Sep 24, 2019

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

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.
Sep 24, 2019
ModifiedValue(issue.getCustomFieldValue(customField), issue.getDueDate())

target field: issue.getCustomFieldValue(customField)

source field: issue.getDueDate()  

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.
Dec 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.
Sep 23, 2019

hey @GS1337,

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

BR,

Leo

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

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