Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,363,989
Community Members
 
Community Events
168
Community Groups

Need Help in Script

Hi Team.

We have created a script to auto populate the target completion date using priority 

Here TCD should be calculated using Created date + Days based on Priority 

We are getting Error where i marked as BOLD

The Script is 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue
import com.opensymphony.workflow.InvalidInputException
import java.sql.Timestamp;
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.Option
import groovy.time.*
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.config.PriorityManager
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.sal.api.user.UserManager

import static com.atlassian.jira.issue.IssueFieldConstants.PRIORITY

def constantsManager = ComponentAccessor.getConstantsManager()

def userUtil = ComponentAccessor.getUserUtil()
log.debug ComponentAccessor.getComponent(UserManager)

//Getting Priority of the issue.
def priority = issue.getPriority()
def pname=priority.name.toString()

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()

Issue issue = issue

def TargetCompletionDate = customFieldManager.getCustomFieldObject("customfield_40742")

Calendar cal = Calendar.getInstance();
Date Created = issue.getCreated()
def temp = cal.getTimeInMillis();
def add = 0;
def x = 1000*24*60*60L
def mydueDate = new Timestamp(cal.getTimeInMillis());

if (pname == "0")
{
add = 21*x
temp = Created +add
mydueDate.setTime(temp)

issue.setCustomFieldValue(TargetCompletionDate, mydueDate)

def currentUserObj = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issueManager.updateIssue(currentUserObj, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

}
else if (pname == "1")
{
add = 35*x
temp = Created+add
mydueDate.setTime(temp)

issue.setCustomFieldValue(TargetCompletionDate, mydueDate)

def currentUserObj = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issueManager.updateIssue(currentUserObj, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

}
else if (pname == "2")
{
add = 70*x
temp = Created+add
mydueDate.setTime(temp)

issue.setCustomFieldValue(TargetCompletionDate, mydueDate)

def currentUserObj = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issueManager.updateIssue(currentUserObj, issue, EventDispatchOption.DO_NOT_DISPATCH, false)

}else if(pname == "3")
{
add = 140*x
temp = Created + add
mydueDate.setTime(temp)

issue.setCustomFieldValue(TargetCompletionDate, mydueDate)

def currentUserObj = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issueManager.updateIssue(currentUserObj, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
}
else if(pname == "4")
{
add = 140*x
temp = Created +add
mydueDate.setTime(temp)

issue.setCustomFieldValue(TargetCompletionDate, mydueDate)

def currentUserObj = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issueManager.updateIssue(currentUserObj, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
}

 

Please Help Me

Thanks 

 

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events