Hi,
We are trying to write a script for a scripted field.
Our scenario is that we have a custom number field (Sprint Variance) and a scripted one (Max Sprint). Our Epic will be put into an current sprint variance will indicate that it may take up to x additional sprints before it’s resolved. Based on the current Sprint Name (e.g. UI Sprint 34) and Sprint Variance (2), we want the scripted field to display (UI Sprint 36).
Obviously the assumption here is that the numbers are at the end of the sprint name and after the word "Sprint". Does anyone have any ideas on how to write this script as I’m struggling to devise the correct syntax and methods :(
In advance I appreciate your help!
Please try the following code in a scripted field. This should do what you want, assuming Sprint Variance is a number custom field.
import com.atlassian.greenhopper.service.sprint.SprintIssueService import com.atlassian.jira.component.ComponentAccessor import com.onresolve.scriptrunner.runner.customisers.JiraAgileBean @JiraAgileBean SprintIssueService sprintIssueService def customFieldManager = ComponentAccessor.getCustomFieldManager() def sprintVarianceCf = customFieldManager.getCustomFieldObjectByName("Sprint Variance") def loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() def sprintResult = sprintIssueService.getActiveSprintForIssue(loggedInUser, issue) def variance = issue.getCustomFieldValue(sprintVarianceCf) as Integer def activeSprint = sprintResult.get().getOrElse(null) def sprintName = activeSprint.name if (! variance || ! activeSprint) { // variance or active sprint not set so no max sprint return null } def tokenizedSprintName = sprintName.tokenize(" ") // remove old variance def sprintNumber = tokenizedSprintName.pop().toInteger() // calculate new variance tokenizedSprintName.push(sprintNumber + variance) // join tokens together tokenizedSprintName.join(" ")
Let us know how you get on with that.
Please also see our documentation around working with JIRA Agile here.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Darren,
They are just static type checking errors. The script will still work as expected when added and run.
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.
Are you on the view epic screen with a "Sprint Variance custom field set as a number custom field?
Also is your sprint called something like "UI Sprint 2"?
Then you should see this appear.
Do you see any errors in the log file when you view the epic?
Which version of JIRA and ScriptRunner do you have?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I edited the script a while ago, I think you have the old version. Please update it and try again.
Also the epic should be in an active sprint.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Copied and pasted provided run again but the field still doesnt display.
I'm the EPIC via the normal issue view screen
Current sprint is called SEPI Sprint 32
Logs show:
[onresolve.scriptrunner.customfield.GroovyCustomField] Script field failed on issue: SEPI-793, field: Max Sprint
groovy.lang.MissingMethodException: No signature of method: com.atlassian.greenhopper.service.sprint.SprintIssueServiceImpl.getActiveSprintForIssue() is applicable for argument types: (com.atlassian.jira.user.BridgedDirectoryUser, com.atlassian.jira.issue.IssueImpl) values: [MYEMAIL:10000, SEPI-793]
Possible solutions: getActiveSprintForIssue(com.atlassian.jira.user.ApplicationUser, com.atlassian.jira.issue.Issue)
at Script533.run(Script533.groovy:14)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Darren,
What version of JIRA and JIRA Software/Agile do you have?
There's a few JIRA Agile versions where some of these methods were changed so that may be causing the issue. Let me know and I'll provide an alternative.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks
Our JIRA version is 6.4.7 and Scriptrunner is 4.1.3.24
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You should use the following script for JIRA 6:
import com.atlassian.greenhopper.service.sprint.SprintIssueService import com.atlassian.jira.component.ComponentAccessor import com.onresolve.scriptrunner.runner.customisers.JiraAgileBean @JiraAgileBean SprintIssueService sprintIssueService def customFieldManager = ComponentAccessor.getCustomFieldManager() def sprintVarianceCf = customFieldManager.getCustomFieldObjectByName("Sprint Variance") def loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getUser() def sprintResult = sprintIssueService.getActiveSprintForIssue(loggedInUser, issue) def variance = issue.getCustomFieldValue(sprintVarianceCf) as Integer def activeSprint = sprintResult.get().getOrElse(null) def sprintName = activeSprint.name if (! variance || ! activeSprint) { // variance or active sprint not set so no max sprint return null } def tokenizedSprintName = sprintName.tokenize(" ") // remove old variance def sprintNumber = tokenizedSprintName.pop().toInteger() // calculate new variance tokenizedSprintName.push(sprintNumber + variance) // join tokens together tokenizedSprintName.join(" ")
Only change was this line:
def loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getUser()
JIRA 6 and 7 have different users either an ApplicationUser or directory User.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Aplogies for the delay...been on annual leave
Thanks, this works!!
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.