Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Link release date to end date

Ксения October 14, 2018

Good day! Is it possible to link the release date to the "end date" of the tasks that it includes. For example, change the release date and automatically change the "end date" tasks that are included in this release.

3 answers

2 accepted

0 votes
Answer accepted
Ксения November 6, 2018

@Orkun GedikAre you here?

Orkun Gedik
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.
November 7, 2018

Hi,

Sorry for late respons @Ксения and my bad in script. I forgot the get current issue from current event. Can you please change the following code with the warning.

MutableIssue currentIssue   = (MutableIssue) event.issue

 

Regards.

Andrey Ozerov November 7, 2018

Hi,

now it working, but with result "null". 

 

@Ксения,  check please.

 

@Orkun Gedik

This script working after any task update, correct?

Only for task from project "Cистема электронного документооборота"

Sorry for stupid question, we newer use scripts before.image.png

Orkun Gedik
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.
November 7, 2018

Hi,

No problem @Andrey Ozerov :) Yes it works when issue updated event fired in project "Cистема электронного документооборота".

Ксения November 7, 2018

@Andrey Ozerov@Orkun GedikIt's not working :(

Changed the release date, end date has not changed in the task.

Безымянный.jpg

Orkun Gedik
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.
November 7, 2018

Please make sure the field names and ids in the script. Also, can you check your jira logs please and let me know if there is a error about script. @Ксения

Ксения November 7, 2018

@Andrey Ozerov, check please

Ксения November 12, 2018

@Orkun Gedik, hello!

Tell me please, what exactly is in those quotation marks to write? Now there is "insert the name of the desired field».

0 votes
Answer accepted
Orkun Gedik
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.
October 15, 2018

Hello @Ксения,

 

Yes it is possible. You can use a listener to update your customfields based on another changes on another customfield. If you have Script Runner plugin in your Jira, let me know if you need help for implementing your listener.

 

Orkun Gedik

Regards.

Ксения October 17, 2018

Thank you, Gedik!

Yes, Script Runner is. Please tell me how the query should look like to make the end date task equal to the release date?

Orkun Gedik
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.
October 17, 2018

You are welcome @Ксения.

You can use Script Listener with IssueUpdated event. I wrote a script for you. Let me know if you have a question and don't forget to update the names and ids of your customfields in script.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.ApplicationUser

MutableIssue currentIssue = (MutableIssue)issue
ApplicationUser currentuser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def releaseChange = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "Release CF Date Name Here"}
def endChange = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "End Date CF Name Here"}

if(releaseChange || endChange) {
CustomField endDateCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("endDateId")
CustomField releaseDateCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("releaseDateId")

if (releaseChange) {
currentIssue.setCustomFieldValue(endDateCF, releaseDateCF.getValue(currentIssue))
} else if (endChange) {
currentIssue.setCustomFieldValue(releaseDateCF, endDateCF.getValue(currentIssue))
}

ComponentAccessor.getIssueManager().updateIssue(currentuser, currentIssue, EventDispatchOption.DO_NOT_DISPATCH, false)
}
Ксения October 26, 2018

Hello, Gedik.

Help me, please :)

screenshot-1.png

 

What should I do in line 7?

Ксения October 29, 2018

@Orkun Gedik, hello!

Help me, please :)

 screenshot-1.png

 

What should I do in line 7?

Orkun Gedik
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.
October 29, 2018

Hello @Ксения,

Is it Script Console? Because you cannot get the current issue with "issue" paramater in Script Console. You should place this script in a listener

Andrey Ozerov November 1, 2018

Hi , @Orkun Gedik

In Custon Listener- 

image.png

0 votes
Ксения November 14, 2018

@Orkun Gedik, hello!

Tell me please, what exactly is in those quotation marks to write? Now there is "insert the name of the desired field».

Ксения November 19, 2018

@Orkun GedikAre you here?)

Andrey Ozerov May 13, 2019

import com.atlassian.jira.event.project.VersionUpdatedEvent
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder


def event = event as VersionUpdatedEvent
def version = event.version

def issueManager = ComponentAccessor.getIssueManager()

def user = ComponentAccessor.getUserManager().getUserByName("jira.bot")

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObjectByName('End date')

def searchService = ComponentAccessor.getComponent(SearchService)
def queryParser = ComponentAccessor.getComponent(JqlQueryParser)

def query = queryParser.parseQuery("project = JRA and resolution is empty")
def search = searchService.search(user, query, new PagerFilter())

search.results.each {documentIssue ->
log.debug(documentIssue.key)


MutableIssue issue = issueManager.getIssueObject(documentIssue.id)
cField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cField), version.getReleaseDate()), new DefaultIssueChangeHolder())
}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events