Me:
I do not know JavaScript, Groovy, etc. I'm familiar with programming concepts and can read my way through code, but I'm not capable of crafting my own code for what I need to do with Jira. I've read through some related answers but my own needs differ enough and I'm not certain I know how to encode the differences.
My Jira instance and relevant add-ons:
Jira server 7.13.1; Adaptivist ScriptRunner; Automation For Jira
What I'm trying to do:
I'm looking to update two custom date fields (Review Date, Projected Completion Date) of certain issue types (Story, Bug, Defect) whenever the Release Date of the FixVersion changes. The two custom fields (Review Date, Projected Completion Date) should match the Release Date.
Some articles I've found and the issues I've run into:
The two articles below mention having a release date display on the ticket. This was useful, but I was unable to find a way to use this value in Automation For Jira. It's not an option in the GUI and I was only getting "invalid JSON" when I worked in the advanced section.
https://community.atlassian.com/t5/Jira-questions/Display-version-release-date-in-issue/qaq-p/153662]
https://community.atlassian.com/t5/Marketplace-Apps-Integrations/Update-Custom-Field-Value-with-Version-Release-Date/qaq-p/624689
The next link was promising in that it updates Due Date with Release Date. However, I'm not certain what I would/wouldn't need to import since I'm using custom date fields. I'm also not certain how to limit by issue type and update with custom fields rather than Due date.
Here's the relevant code from the link above:
issues.each{ issue ->
issue.setDueDate(new java.sql.Timestamp(date.getTime()))
issueManager.updateIssue(appUser, issue, EventDispatchOption.ISSUE_UPDATED, false)
This other article shows how to update a custom date field by release date, but I'm not certain when this event occurs or where to include this code. Is this a scripted field? If so, I still don't believe I can use it in Automation for Jira.
Any advice? Need more information from me that would be helpful?
You can create a listeners using SR4J to look for Version update event and update the dates. The links you shared above already have enough information to get you started.
- You need to create a custom listener.
- Learn how to update custom field value.
- Get familiar with handling dates.
Share your code (if you have started writing it) and we can take a look at it.
Ravi
Also you can refer to library for lot of sample code.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Ravi Sagar _Sparxsys_ - Thanks.
I've cobbled together the below mainly by copying code from the support articles I linked. I've added some comments where I've had questions/concerns
If you could take a look, I'd appreciate it
//copied the below import items from a few different articles
//added one called customFieldManager
//uncertain if I need them all or not
import com.atlassian.jira.event.project.VersionUpdatedEvent
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.customFieldManager
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.bc.issue.IssueService
import org.apache.log4j.Level
import org.apache.log4j.Logger
import com.atlassian.jira.event.type.EventDispatchOption
//the below code is copied from one of the support articles linked
def appUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def searchService = ComponentAccessor.getComponent(SearchService.class)
def issueManager = ComponentAccessor.getIssueManager()
def log = Logger.getLogger("Jira Log")
log.setLevel(Level.DEBUG)
def name = event.getVersion().getName()
def date = event.getVersion().getReleaseDate()
def jqlSearch = "fixVersion = \"${name}\""
//uncertain if below is proper way to identify my custom fields
def reviewDate = issue.getCustomFieldValue(cf_11300)
def projectedCompletionDate = issue.getCustomFieldValue(cf_11001)
SearchService.ParseResult parseResult = searchService.parseQuery(appUser, jqlSearch)
if(parseResult.isValid())
{
def searchResult = searchService.search(appUser, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
def issues = searchResult.issues.collect {issueManager.getIssueObject(it.id)}
//don't know how to limit the below to relevant issue types (Story, Bug, //Defect)
//also uncertain how to set value on a custom field
issues.each{ issue ->
issue.setCustomFieldValue(reviewDate, new java.sql.Timestamp(date.getTime()))
issue.setCustomFieldValue(projectedCompletionDate, new java.sql.Timestamp(date.getTime()))
issueManager.updateIssue(appUser, issue, EventDispatchOption.ISSUE_UPDATED, false)
}
}else {
log.error("Invalid JQL: " + jqlSearch)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Ravi Sagar _Sparxsys_ - Not sure what happened. I posted a reply with code but it seems to have vansihed. Adding again:
//copied the below import items from a few different articles
//added one called customFieldManager
//uncertain if I need them all or not
import com.atlassian.jira.event.project.VersionUpdatedEvent
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.customFieldManager
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.bc.issue.IssueService
import org.apache.log4j.Level
import org.apache.log4j.Logger
import com.atlassian.jira.event.type.EventDispatchOption
//the below code is copied from one of the support articles linked
def appUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def searchService = ComponentAccessor.getComponent(SearchService.class)
def issueManager = ComponentAccessor.getIssueManager()
def log = Logger.getLogger("Jira Log")
log.setLevel(Level.DEBUG)
def name = event.getVersion().getName()
def date = event.getVersion().getReleaseDate()
def jqlSearch = "fixVersion = \"${name}\""
//uncertain if below is proper way to identify my custom fields
def reviewDate = issue.getCustomFieldValue(cf_11300)
def projectedCompletionDate = issue.getCustomFieldValue(cf_11001)
SearchService.ParseResult parseResult = searchService.parseQuery(appUser, jqlSearch)
if(parseResult.isValid())
{
def searchResult = searchService.search(appUser, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
def issues = searchResult.issues.collect {issueManager.getIssueObject(it.id)}
//don't know how to limit the below to relevant issue types (Story, Bug, Defect)
//also uncertain how to set value on a custom field
issues.each{ issue ->
issue.setCustomFieldValue(reviewDate, new java.sql.Timestamp(date.getTime()))
issue.setCustomFieldValue(projectedCompletionDate, new java.sql.Timestamp(date.getTime()))
issueManager.updateIssue(appUser, issue, EventDispatchOption.ISSUE_UPDATED, false)
}
}else {
log.error("Invalid JQL: " + jqlSearch)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.