I am attempting to populate two custom fields on an Issue based off the Sprint dates of a linked Story. The Sprint Start and End Date Fields are DateTime, and the Field I'm attempting to populate is just a DatePicker.
Below is the script I have written so far. When I execute it nothing happens. The Old and New dates from within the logger are still the same.
Clearly,
estStart.updateValue(null,parent,new ModifiedValue(sprintstartValue, estSOld),changeHolder)
isn't updating the value, but I'm not sure why. Any help is really appreciated.
import com.atlassian.jira.issue.ModifiedValue;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.link.IssueLink;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;
import com.atlassian.jira.bc.issue.search.SearchService;
import com.atlassian.jira.user.util.UserUtil;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.issue.search.SearchResults;
import com.atlassian.jira.web.bean.PagerFilter;
import org.apache.log4j.Logger
import org.apache.log4j.Level
def log = Logger.getLogger("")
log.setLevel(Level.DEBUG)
log.debug("Script started")
//JQL for all stories in a Sprint
String jqlSearch = "key in (PRO4SIGHT-238)"
SearchService searchService = ComponentAccessor.getComponent(SearchService.class)
UserUtil userUtil = ComponentAccessor.getUserUtil()
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
IssueManager issueManager = ComponentAccessor.getIssueManager()
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def changeHolder = new DefaultIssueChangeHolder()
List<MutableIssue> issues = null
//List of variables
def output = ""
def parent = ""
def estSOld = ""
def estSNew = ""
def sprintId = 10000
def sprint = customFieldManager.getCustomFieldObject(sprintId)
def estStartId = 21603
def estStart = customFieldManager.getCustomFieldObject(estStartId)
SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlSearch)
//Verifies that the JQL is valid
if (parseResult.isValid()) {
SearchResults searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
issues = searchResult.getResults().collect {issueManager.getIssueObject(it.id)}
//Starts the iteration through all stories in the JQL
issues.each { it ->
//Pulls the Sprint Start and End Dates into two variables
def sprintstartValue = it.getCustomFieldValue(sprint)?.startDate.first()?.toDate()
log.debug(sprintstartValue)
def sprintendValue = it.getCustomFieldValue(sprint)?.endDate.last()?.toDate()
log.debug(sprintendValue)
//Searches for the parent Feature of the Story
def links = ComponentAccessor.getIssueLinkManager().getOutwardLinks(it.getId())
for( l in links) {
if(l.issueLinkType.name == "Parent of") {
output = output + l.issueLinkType.name + ": " + l.getDestinationObject() + "<br/>"
parent = l.getDestinationObject()
//Gets the Old value for the Field thats getting changed
estSOld = parent.getCustomFieldValue(estStart)
log.debug(estSOld)
//Sets the New Value to match the Sprint Start Date
estStart.updateValue(null,parent,new ModifiedValue(sprintstartValue, estSOld),changeHolder)
estSNew = parent.getCustomFieldValue(estStart)
log.debug(estSNew)
}
}
}
}
Right after posting this I found the issue..
estStart.updateValue(null,parent,new ModifiedValue(sprintstartValue, estSOld),changeHolder)
is backwards. It should be
estStart.updateValue(null,parent,new ModifiedValue(estSOld, sprintstartValue),changeHolder)
However, now I'm getting the error:
java.lang.IllegalArgumentException: Java type java.util.Date not currently supported. Sorry.
This is probably a date formatting issue right? How can I format the Sprint Dates to work with a DatePicker?
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.