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 issuedef p(Object o, String name) { println name + " (" + o.class + "): " + o.toString() }// Values before updatep(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 issueissue.setFieldValue("Target end", issue.get("duedate"))p(issue.get("Target end"), "Target end updated v1")// Update v2 - adjusting for timezone issuedef 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 valuep(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.
hey @Sebastian Gastager,
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"
@Sebastian Gastager
Try something like this:
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.event.type.EventDispatchOptionimport com.atlassian.jira.issue.fields.CustomFieldimport com.atlassian.jira.util.ImportUtilsimport com.atlassian.jira.issue.index.IssueIndexManagerimport com.atlassian.jira.issue.ModifiedValueimport com.atlassian.jira.issue.util.DefaultIssueChangeHolderdef indexManager = ComponentAccessor.getComponent(IssueIndexManager)def issueService = ComponentAccessor.issueServicedef loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUserdef 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 valuesboolean 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
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?
Hi @Sebastian Gastager 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.
It looks like you're new here. Sign in or register to get started.