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)
}
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)
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @PD Sheehan
I have tried both the above scripts and i see errors in the script..
Also i see null is being returned from getFieldByName("Sprint")
It says 'No such property: state for class: java.lang.Object
'No such property: value for class: java.lang.Object
Is there something i am missing as i am not execute above code..
Can you help me on this
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.