I am new to script runner. I want to copy a date custom field from issue 1 to linked issue. I have Jira 7.6.1 sever and script runner.
I have successfully been able to do this with other fields for description, people, but the date field won't populate with a date. It returns "invalid date" and under these words I can see this $datePickerFormatter.format($value) but very briefly. I do not have listeners setup for any of the fields that do work.
my code is this: I do have a parent script set up, but not sure that it is needed. Should I allow for fields without a date and how would I do that?
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def fieldSizingStatusDate = customFieldManager.getCustomFieldObject("customfield_16900")
def linkedSizingStatusDate
issueLinkManager.getOutwardLinks(issue.id)?.each {issueLink ->
if (issueLink.issueLinkType.name == "Sizes") {
linkedSizingStatusDate = issueLink.getDestinationObject().getCustomFieldValue(fieldSizingStatusDate)
}
}
return linkedSizingStatusDate
Hi,
Assuming this is a code for a scripted field, make sure that:
1) You have created your scripted field using the 'Date Time Picker' template.
2) The searcher for that field is set to 'Date Time searcher'
3) If your 'customfield_16900' is a 'Date Picker' type field, then you should get its value like so:
issueLink.getDestinationObject().getCustomFieldValue(fieldSizingStatusDate)
and then return it in your scripted field
Hi Ivan,
Changing the code work. Thanks!
With the template set to Date Time Picker and the searcher set to Date Time Range Picker. The date field appears on the right with all the other date fields (yeah) but instead of the date it says "2 days ago", when it should say 06/11/2018, which could be 2 days ago.
With the template set to Text Field or Absolute Date Time and the searcher set to Date Time Range picker then the field appears on the left (boo) but with the date (yeah).
Any ideas? I have no idea how it is getting the "2 days ago"
Thank you so very much for your reply!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That one's easy enough. The reason why you see things like '2 days ago' is because by default Jira has relative dates enabled. Check out this KB article on how to disable it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ivan,
I will have to have my server team make that change. I was wondering why it was working in one environment but not the other. This explains it.
Thank you so very much for your reply!! I really appreciate it!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Linda H
Try like below :
import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.fields.CustomField import static java.lang.Math.* import java.sql.Timestamp // get current issue Issue issue = issue customFieldManager = ComponentManager.getInstance().getCustomFieldManager() // Getting custom field value sourceDate = issue.getCustomFieldValue( customFieldManager.getCustomFieldObjectByName("sourceDateField") ) as Date // Getting custom field object destinationDateObj = customFieldManager.getCustomFieldObjectByName("destinationDateField")
issue.setCustomFieldValue(destinationDateObj, sourceDate)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.