It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to check if sprint is active in behaviours

Mihai Mihai Apr 23, 2019

Hello,

 

Using Behaviours - from Scriptrunner, I would like to check if a sprint is active. If that is true, then I would like to make a certain field (Story Points) read-only.

 

Please let me know how to check if the sprint is active.

 

Thank you!

 

This is what I have so far:

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.greenhopper.service.rapid.view.RapidViewService
import com.atlassian.greenhopper.service.sprint.Sprint


def SprintField = getFieldById("Sprint")
def StoryPointsField = getFieldById("Story Points")


if (SprintField.state == Sprint.State.ACTIVE) {

StoryPointsField.setReadOnly(true)

}

1 answer

1 accepted

1 vote
Answer accepted
Peter-Dave Sheehan Apr 23, 2019

The "getFieldById" method from Behaviors returns a "formField" object. This is a scriptrunner/behavior class I think. Not a native class from Jira.

And the value stored in the formField is probably just the sprint Id.

So you'll need to get a customField object then lookup the value from the underlying issue.

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.customFieldManager

def sprintFormField = getFieldByName("Sprint")
def storyPtFormField = getFieldByName("Story Points")

def sprintCustField = customFieldManager.getCustomFieldObject(sprintFormField.fieldId)
sprint = issueContext.getCustomFieldValue(sprintCustField)

if(sprint && sprint.state == "ACTIVE"){
storyPtFormField.setReadOnly(true)
} else {
storyPtFormField.setReadOnly(false)
}

If you need to react to newly selected sprint values, then you'll need to fetch those details using the SprintManager.

Something along those lines may work:

import com.atlassian.greenhopper.service.sprint.SprintManager
import com.onresolve.scriptrunner.runner.customisers.JiraAgileBean
@JiraAgileBean
SprintManager sprintManager

def sprintFormField = getFieldByName("Sprint")
def storyPtFormField = getFieldByName("Story Points")
storyPtFormField.setReadOnly(false)

if(sprintFormField.value){
def sprint = sprintManager.getSprint(sprintFormField.value as Long)
if(sprint.isValid() && sprint.value.state == "ACTIVE" ){
storyPtFormField.setReadOnly(true)
}
}
Mihai Mihai Apr 24, 2019

Thank you very much, this works great!

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Jira

Try Jira Cloud for Outlook: Organize your work without leaving your inbox

Hi Atlassian community, My name is Max and I work on the product integration team at Atlassian. I am pleased to announce the early access program for the Jira Cloud add-in for Outlook. This add-in...

2,181 views 6 15
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you