I'm trying to write a Listener in Scriptrunner JIRA Server
It does a fast-track transition of an issue when a user inputs an issue to the concrete sprint
Event: Issue Updated
Condition:
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.greenhopper.service.rapid.view.RapidViewService
import com.atlassian.greenhopper.service.sprint.SprintIssueService
import com.atlassian.greenhopper.service.sprint.SprintManager
import com.atlassian.greenhopper.service.sprint.SprintService
import org.apache.log4j.Logger
import org.apache.log4j.Level
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def sprintField = customFieldManager.getCustomFieldObjectByName("Sprint");
def sprints = event.issue.getCustomFieldValue(sprintField);
sprints?.id?.equals(1837);
Action: transition to status
I've tried several variants, but it doesn't work. I think that the problem is in this line:
sprints?.id?.equals(1837);
Hi @Анна Рыбина,
if the issue is passed from one to another sprint it has more than one value and it'll be returned as List
I'm not quite sure to simplify the condition but below snippet is working fine in my sandbox
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.greenhopper.service.sprint.Sprint
def sprints = issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName("Sprint")[0])
def isSprint = false
sprints.each{
Sprint s = it as Sprint
if(s.id == 835){
isSprint = true
}
}
return isSprint
hope this helps
BR,
Leo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Leo But maybe you can help me or advice anything for similar problem, but when Sprint field is empty
I'm trying to transition an issue to status called "Backlog" when an issue is moved to backlog
But nothing like comparing Sprint value field with null works, even with the help of your code above
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Анна Рыбина, it is quite easy only.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.greenhopper.service.sprint.Sprint
def sprints = issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectsByName("Sprint")[0])
if(sprints){
return false // sprint has some value
}else{
return true // sprint field is empty/null
}
Note: this will only work if the issue is assigned to single sprint and move to backlog.
if the issue is transferred from one to another sprint this condition will fail
BR,
Leo
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.
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.