Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to set the value of Fix Version field in an issue through groovy script?

Tony Mackin May 15, 2018

We are planning to use Jira Software to track projects and tasks for a certain team.   This team wont be doing code releases so don't need to track versions.

However they want to always set the fix versions field to the same value so can use the backlog board  and version view option to see all items for their team.

---

How can a post-function script be used to always set the value of the fix versions field to be a default value.   For example say always want version field to be ABC.

 

I tried creating a post-function with the script here

https://community.atlassian.com/t5/Jira-questions/How-to-set-the-value-of-fix-version-default-field-in-an-issue/qaq-p/295929

but I get a runtime error on the line this line due to null pointer (versionn = null)

issue.setFixVersions(Arrays.asList(versionn)) 

 

2 answers

1 accepted

0 votes
Answer accepted
Tony Mackin May 17, 2018

Thanks Alexey for your help.   This is now working.

verssionn came back as null.

I figured out problem with script thanks to your help and looking values of the fields in console messages.

 

In line 9 of script above it had  "WCE Security" but the actual Fix Version defined in Jira is "WCE Security Team".    Once I changed line 9 to look for the right value the script now works to automatically sets the Fix Version in all new issues created.

1 vote
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 15, 2018

It should be like this:

def version = ComponentAccessor.getVersionManager().getVersion(issue.getProjectId, "ABC");

issue.setFixVersions(Arrays.asList(version))
Tony Mackin May 16, 2018

Thanks - I modified the script with line above and getting  a run time error.

Any advise would be greatly appreciated.

 

In Jira project there is one version setup with value of WCE Security

 

Post-function script on Create transiton is:

1   // Script to set value of Version for WCE Security Project issues
2   import com.atlassian.jira.project.version.Version
3   import com.atlassian.jira.project.version.VersionManager
4   import com.atlassian.jira.issue.fields.CustomField
5   import com.atlassian.jira.component.ComponentAccessor
6   import com.atlassian.jira.project.Project
7   VersionManager versionManager = ComponentAccessor.versionManager
8
9  String valueOfversion = "WCE Security"
10 Version versionn = versionManager.getVersion(issue.getProjectId(), valueOfversion)
11 issue.setFixVersions(Arrays.asList(versionn))
12 def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
13 log.warn ("+++ Issue " + issue  + " valueOfversion = " + valueOfversion +  " versionn = " + versionn)
14 ComponentAccessor.getIssueManager().updateIssue(user, issue, com.atlassian.jira.event.type.EventDispatchOption.DO_NOT_DISPATCH, false)

 

And it gives this error message.... line 11 fails, with null value for versionn I believe:

2018-05-16 16:21:00,872 https-jsse-nio-9445-exec-4 ERROR (my email) 980x29159x1 ckzv38 (IP) secure/QuickCreateIssue.jspa [c.o.s.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: null, actionId: 1, file: <inline script>
java.lang.NullPointerException
 at Script1.run(Script1.groovy:11)  
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 16, 2018

Could you log the variable versionn before line 11?

log.error("versionn: " + versionn)

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 17, 2018

@Tony Mackin It is very good to hear that it worked for you!

Suggest an answer

Log in or Sign up to answer