Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,411,393
Community Members
 
Community Events
169
Community Groups

How to check if sprint is active in behaviours

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

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)
}
}

Thank you very much, this works great!

Suggest an answer

Log in or Sign up to answer