ScriptRunner: Add issue to sprint or change sprint for issue

Hello,

I want to add an issue to a sprint (or remove it from one sprint and add it to another). Is there a way to do this using ScriptRunner?

Any help is much appreciated!

Thanks!

1 answer

Please use one of the ScriptRunner tags in future... 

Does https://scriptrunner.adaptavist.com/latest/jira/builtin-scripts.html#_add_remove_from_to_active_sprint not cover what you need to do? 

How can I use it in a ScriptRunner script?

Here is some background information:

We import data from aha and want to keep Fix Version/s and Sprint aligned, meaning our Fix Version/s and Sprints for a specific project have exactly the same names and exist already. aha just sets Fix Version/s, in JIRA we use Sprints. 

To keep them aligned automatically I added an issue updated listener, that recognizes either a Sprint or a Fix Version/s change in an issue ticket. If the Sprint value changed, Fix Version/s gets set accordingly. This works fine. I have the same logic in place in case Fix Version/s changes. Only getting the Sprint object fails. My approach was to get the Sprint through:

CustomField cf = customFieldManager.getCustomFieldObjectByName('Sprint');
def fieldConfig = cf.getRelevantConfig(issue);
def sprint = ComponentAccessor.optionsManager.getOptions(fieldConfig).find({ it == fixVersionName })?.first();
...

then set it with:

MutableIssue mutableIssue = issueManager.getIssueObject(issue.id);
       	sprintField.updateValue (null, issue, new ModifiedValue(issue.getCustomFieldValue(sprintField), sprint), new DefaultIssueChangeHolder());

Unfortunately I always get an empty option list...

 

The whole value change logic is in this script, thus it would be nice if it's also possible to handle the Sprint change for an issue there.

Thank you for the workflow function Jamie.  How can I make that fire one a ticket move event?

So I'm thinking about adding it to the Create workflow step as a post function.

I see it can take conditions.

What do I need to do to ensure that it only fires if the Create is a result of a Ticket Move event?

Thanks, 

Randy James

Suggest an answer

Log in or Sign up to answer
Community showcase

Scrum Roles Explained: the Do's and the Don'ts

Hello Community,  Today we are going to talk about the three Scrum Roles. There is the Development Team, the Scrum Master and the Product Owner. In my opinion these three are all really impo...

57 views 0 4
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you