Hi
I want to Update Custom end Date Field with this value:
end date = start date + original estimate
I think and check different methods and the last one is to use "Execute a ScriptRunner script" in Automation for Jira Plugin. I use the server version of Jira:
Here my code, I'm new to groovy, Please help me to complete it:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import java.sql.Timestamp
import java.time.DayOfWeek
import java.text.SimpleDateFormat;
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.event.type.EventDispatchOption
def myissue = issue as Issue
// Set the logging leve to DEBUG
import org.apache.log4j.Level
log.setLevel(Level.DEBUG)
Issue issueKey = issue
def id=issueKey.getId()
// Get access to the Custom Field Manager
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
// Get the required custom field values
def StartDate = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Start Date'}
def EndDate = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'End Date'}
def startDateVal = StartDate.getValue(issue)
def endDateVal = EndDate.getValue(issue)
def ost = issue.getOriginalEstimate()
def rst = issue.getEstimate()
def updated = myissue.getUpdated()
myissue.setCustomFieldValue(EndDate, new Timestamp(startDateVal-ost).Date)
hey @Ansar Rezaei
We have recently published a kb article to add Orginal estimate to a date field using Automation for Jira. Hope this helps :)
Thanks
Swati
Hi Swati,
can you help with jira server how to implement same automation.
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I found the answer:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.IssueInputParameters
import org.apache.log4j.Logger
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
def mylog = Logger.getLogger("com.onresolve.jira.groovy")
def userManager = ComponentAccessor.getUserManager()
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(10403)
def issueManager = ComponentAccessor.getIssueManager()
def user = userManager.getUserByName("Jira Administrator")
def startdate = ComponentAccessor.getCustomFieldManager().getCustomFieldObject("customfield_10402");
def startdatevalue = issue.getCustomFieldValue(startdate) as Date
def oestimate = issue.getOriginalEstimate()/(3600*8) as int
def customFieldValue = startdatevalue + oestimate
def customFieldOldValue = issue.getCustomFieldValue(customField)
customField.updateValue(null, issue, new ModifiedValue(customFieldOldValue, customFieldValue), new DefaultIssueChangeHolder())
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.