How to get Release Date and Clear due date if the Fix version is set to Empty via Script runner

Rodolfo So September 7, 2020

Hi ,

 

I would like to get the Release date from the Fix version and Clear the due date if the Fix version is setup to Empty. I'm not good in scripting, can someone help on this?

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.project.version.Version
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.IssueManager
import java.util.ArrayList;
import java.util.Collection;


Collection<Version> fixVersions = new ArrayList<Version>();
IssueManager issueManager = ComponentAccessor.getComponent(IssueManager.class)
def customFieldManager = ComponentAccessor.getCustomFieldManager()

 

//Custom field for Due date
def cDuedate = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_12111")
def cDuedateValue = event.issue.getCustomFieldValue(cDuedate)

def issue = (MutableIssue)event.issue
def version = (Version)issue.getFixVersions().first()
def setDate = version.getReleaseDate() as Date

def issueVersions = event.issue.getFixVersions()
def fixVersion= issue.getFixVersions()
log.warn "Release Date = ${setDate}"

//if (fixVersion.empty) {
if (issue.fixVersions*.name.contains("None")){
issue.setCustomFieldValue (cDuedate,null)
issueManager.updateIssue(event.getUser(), issue , EventDispatchOption.ISSUE_UPDATED, false)

} else {
issue.setCustomFieldValue (cDuedate,setDate)
issueManager.updateIssue(event.getUser(), issue , EventDispatchOption.ISSUE_UPDATED, false)
}

1 answer

0 votes
Bill Sheboy
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 28, 2020

Hi @Rodolfo So 

Did you see this similar community posting and answer on this topic:

How to use ScriptRunner to update Issue Due Date based on fixVersion release Date

https://community.atlassian.com/t5/Jira-questions/How-to-use-ScriptRunner-to-update-Issue-Due-Date-based-on/qaq-p/1212254

Best regards,

Bill

Suggest an answer

Log in or Sign up to answer