Copy the numeric value of a custom field to the Time Tracking fields (Original Estimated, Remaining Estimated, and Logged).
Could someone please assist me in using Scriprunner to copy custom field values to time tracking?
I have three custom fields (number fields in hours) that I need to copy to Time Tracking when we update the issue in the inline edit view (not in transition).
For example:
Field1 -> Original Estimated.
Field 2 -> Remaining Estimated.
Field3 -> Logged.
I used the following script to copy from a custom field to system field Original Estimate. Replace customfield_13858 to your custom field id.
The trick is to use
All values should be in seconds and of type Long.
//
// This script will copy estimates from a custom number field to the system field Original Estimate
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import java.sql.Timestamp
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)
def issueManager = ComponentAccessor.getIssueManager()
def cfManager = ComponentAccessor.getCustomFieldManager()
// Set the custom field id for the different custom fields
// Values will be copied from Estimated Time, customFieldId=13858
def estimatedTime = cfManager.getCustomFieldObject("customfield_13858")
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
log.warn("Running script for copying times to Original Estimate.")
// Find all issues with Estimated Time set that does not have an Original Estimate
def query = jqlQueryParser.parseQuery("project = OEYAC and \"Estimated Time\" is not EMPTY AND originalEstimate is EMPTY")
def search = searchService.search(user, query, PagerFilter.getUnlimitedFilter())
log.warn("Total issues: ${search.total}")
// Loop through all the issues with Estimated Time set
search.results.each { documentIssue ->
log.warn("Processing issue: ${documentIssue.key}")
// Get a mutable issue
def issue = issueManager.getIssueObject(documentIssue.id)
//Get the current date and create the new date value
def timeEstimate = issue.getCustomFieldValue(estimatedTime) as Long
// Estimated Time is in hours and Original Estimate deals with seconds. 1h = 3600sec
def originalEstimate = timeEstimate * 3600
// Update the new field in the issue
issue.setOriginalEstimate(originalEstimate)
log.warn("Estimated Time: ${timeEstimate}")
log.warn("OriginalEstimate: ${originalEstimate}")
// Save the changes
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
}
Don't forget to reindex the project to make the new estimates available in searches.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Theres a good script for working with fields at https://library.adaptavist.com/entity/update-the-value-of-custom-fields-through-the-script-console
But it doesn't demonstrate the use of system fields.
For the original estimate, you can simply say issue.setEstimate(#) but bear in mind that it stores the estimate as a simple number. I think the number is seconds (it's been a long time since I looked at it) - so you will need to enter 28800 for an estimate of 1 working day (8 hours).
You don't want to set remaining estimate or logged time - they're calculated from the data entered in other places.
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.
Hello @Pramodh M , copy from custom field to custom field works for me but I didn't fine method to copy from a custom field to Time Tracking Origianl Estimate and same for other, Reamining Estimated and Logged.
Could you please help me here how can I do that?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.