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,560,214
Community Members
 
Community Events
185
Community Groups

Set value in version picker

Edited

Hi,

What is the code for setting a string value (text field) into "Fix version/s" (Version Picker)?

this String exists in the versions list.

 

thanks

2 answers

0 votes
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.
Jul 25, 2018

Hello,

The Fix Versions field is a system field, that is why you set it differently from Version Picker. 

You set fix version with the issue.setFIxVersions([version]) method. You set a custom field of the version type with issue.setCustomFieldValue(field, [value]) method. You can find more info here:

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

 

@Alexey Matveev ,

It's not working good for me... Capture2.PNGDo you have an idea ? 

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.
Jul 26, 2018

What are the errors? Is it a post function? Is this post function first in the list of post funcitons? Is it the create issue transition?

it is a script listener, on issue updated

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.
Jul 26, 2018

I see. 

Then you should add this import:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption

 

Then add the following lines to the end of the script:

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)

@Alexey Matveev I missed something...

Capture3.PNG

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.
Jul 26, 2018

Can you provide errors and the whole script?

@Alexey Matveev How can I provide errors ?

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.
Jul 26, 2018 • edited

Hover the mouse over the ComponentAccessor, which is underlined in red. You will see errors. Make a screenshot.

Also provide the whole script

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.project.version.Version
import javax.ws.rs.core.MediaType
import javax.ws.rs.core.MultivaluedMap
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import com.atlassian.jira.issue.changehistory.ChangeHistoryManager
import com.atlassian.jira.issue.history.ChangeItemBean
import com.atlassian.jira.issue.IssueImpl;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption

//IssueManager issueManager = ComponentAccessor.getComponent(IssueManager.class)
//test

def issueManager = ComponentAccessor.getIssueManager();
Issue issue = event.getIssue();
//Issue issue = issueManager.getIssueObject("WBL-57061");

//Issue issue = event.getIssue();
def issueType=issue.getIssueType().name;
if (issueType=="Story" || issueType=="Bug-Internal" || issueType=="Bug-Customer" || issueType=="RFE"
|| issueType=="Sub-Test"
|| issueType=="Sub-Bug")
{
//Get fix versions of issue
Collection<Version> fixVersions = new ArrayList<Version>();
fixVersions = issue.getFixVersions();
def Parent = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Parent Fix Version");
def ParentFixVersion = issue.getCustomFieldValue(Parent);

//Get Epic Link Key
def epic = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Epic Link");
def epicKey = issue.getCustomFieldValue(epic);

if(fixVersions[0]!=ParentFixVersion)
{
UserMessageUtil.error("Failed. Fix version of issue should be like the Epic's fix version");
//ChangeHistoryManager changeHistoryManager = ComponentAccessor.getChangeHistoryManager();
//List<ChangeItemBean> changeList = changeHistoryManager.getChangeItemsForField(issue, "Fix Version")
//return changeList[0].toString.class;
issue.setFixVersions([ParentFixVersion])
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)
}
}Untitled4.pngUntitled5.png

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.
Jul 26, 2018

What is your Jira version? Try to execute this script in a a listnere and have a look in the atlassian-jira.log file. 

Jira v7.3.6.

What is the atlassian-jira.log file.  ?

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.
Jul 26, 2018
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.
Jul 26, 2018

Try to write like this and run the script:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.project.version.Version
import javax.ws.rs.core.MediaType
import javax.ws.rs.core.MultivaluedMap
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import com.atlassian.jira.issue.changehistory.ChangeHistoryManager
import com.atlassian.jira.issue.history.ChangeItemBean
import com.atlassian.jira.issue.IssueImpl;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption

//IssueManager issueManager = ComponentAccessor.getComponent(IssueManager.class)
//test

def issueManager = ComponentAccessor.getIssueManager();
def issue = ComponentAccessor.getIssueManager.getIssueObjectByCurrentKey(event.getIssue().getKey());
//Issue issue = issueManager.getIssueObject("WBL-57061");

//Issue issue = event.getIssue();
def issueType=issue.getIssueType().name;
if (issueType=="Story" || issueType=="Bug-Internal" || issueType=="Bug-Customer" || issueType=="RFE"
|| issueType=="Sub-Test"
|| issueType=="Sub-Bug")
{
//Get fix versions of issue
Collection<Version> fixVersions = new ArrayList<Version>();
fixVersions = issue.getFixVersions();
def Parent = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Parent Fix Version");
def ParentFixVersion = issue.getCustomFieldValue(Parent);

//Get Epic Link Key
def epic = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Epic Link");
def epicKey = issue.getCustomFieldValue(epic);

if(fixVersions[0]!=ParentFixVersion)
{
UserMessageUtil.error("Failed. Fix version of issue should be like the Epic's fix version");
//ChangeHistoryManager changeHistoryManager = ComponentAccessor.getChangeHistoryManager();
//List<ChangeItemBean> changeList = changeHistoryManager.getChangeItemsForField(issue, "Fix Version")
//return changeList[0].toString.class;
issue.setFixVersions([ParentFixVersion])
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)
}
}
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.
Jul 26, 2018
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.project.version.Version
import javax.ws.rs.core.MediaType
import javax.ws.rs.core.MultivaluedMap
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import com.atlassian.jira.issue.changehistory.ChangeHistoryManager
import com.atlassian.jira.issue.history.ChangeItemBean
import com.atlassian.jira.issue.IssueImpl;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption

//IssueManager issueManager = ComponentAccessor.getComponent(IssueManager.class)
//test

def issueManager = ComponentAccessor.getIssueManager();
def issue = ComponentAccessor.getIssueManager().getIssueObjectByCurrentKey(event.getIssue().getKey());
//Issue issue = issueManager.getIssueObject("WBL-57061");

//Issue issue = event.getIssue();
def issueType=issue.getIssueType().name;
if (issueType=="Story" || issueType=="Bug-Internal" || issueType=="Bug-Customer" || issueType=="RFE"
|| issueType=="Sub-Test"
|| issueType=="Sub-Bug")
{
//Get fix versions of issue
Collection<Version> fixVersions = new ArrayList<Version>();
fixVersions = issue.getFixVersions();
def Parent = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Parent Fix Version");
def ParentFixVersion = issue.getCustomFieldValue(Parent);

//Get Epic Link Key
def epic = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Epic Link");
def epicKey = issue.getCustomFieldValue(epic);

if(fixVersions[0]!=ParentFixVersion)
{
UserMessageUtil.error("Failed. Fix version of issue should be like the Epic's fix version");
//ChangeHistoryManager changeHistoryManager = ComponentAccessor.getChangeHistoryManager();
//List<ChangeItemBean> changeList = changeHistoryManager.getChangeItemsForField(issue, "Fix Version")
//return changeList[0].toString.class;
issue.setFixVersions([ParentFixVersion])
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)
}
}

The same error :( start with this line:

def issue = ComponentAccessor.getIssueManager().getIssueObjectByCurrentKey(event.getIssue().getKey());

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.
Jul 26, 2018

What error? No such property? not possible

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.
Jul 26, 2018
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.project.version.Version
import javax.ws.rs.core.MediaType
import javax.ws.rs.core.MultivaluedMap
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import com.atlassian.jira.issue.changehistory.ChangeHistoryManager
import com.atlassian.jira.issue.history.ChangeItemBean
import com.atlassian.jira.issue.IssueImpl;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption

//IssueManager issueManager = ComponentAccessor.getComponent(IssueManager.class)
//test

def issueManager = ComponentAccessor.getIssueManager();
def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey(event.getIssue().getKey());
//Issue issue = issueManager.getIssueObject("WBL-57061");

//Issue issue = event.getIssue();
def issueType=issue.getIssueType().name;
if (issueType=="Story" || issueType=="Bug-Internal" || issueType=="Bug-Customer" || issueType=="RFE"
|| issueType=="Sub-Test"
|| issueType=="Sub-Bug")
{
//Get fix versions of issue
Collection<Version> fixVersions = new ArrayList<Version>();
fixVersions = issue.getFixVersions();
def Parent = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Parent Fix Version");
def ParentFixVersion = issue.getCustomFieldValue(Parent);

//Get Epic Link Key
def epic = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Epic Link");
def epicKey = issue.getCustomFieldValue(epic);

if(fixVersions[0]!=ParentFixVersion)
{
UserMessageUtil.error("Failed. Fix version of issue should be like the Epic's fix version");
//ChangeHistoryManager changeHistoryManager = ComponentAccessor.getChangeHistoryManager();
//List<ChangeItemBean> changeList = changeHistoryManager.getChangeItemsForField(issue, "Fix Version")
//return changeList[0].toString.class;
issue.setFixVersions([ParentFixVersion])
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)
}
}

Ok @Alexey Matveev, Now the setFixVersion has error:

Untitled8.png

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.
Jul 26, 2018

You can skip this error. It will work just fine

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.
Jul 26, 2018

Or do like this:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.project.version.Version
import javax.ws.rs.core.MediaType
import javax.ws.rs.core.MultivaluedMap
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
import com.atlassian.jira.issue.changehistory.ChangeHistoryManager
import com.atlassian.jira.issue.history.ChangeItemBean
import com.atlassian.jira.issue.IssueImpl;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption

//IssueManager issueManager = ComponentAccessor.getComponent(IssueManager.class)
//test

def issueManager = ComponentAccessor.getIssueManager();
def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey(event.getIssue().getKey());
//Issue issue = issueManager.getIssueObject("WBL-57061");

//Issue issue = event.getIssue();
def issueType=issue.getIssueType().name;
if (issueType=="Story" || issueType=="Bug-Internal" || issueType=="Bug-Customer" || issueType=="RFE"
|| issueType=="Sub-Test"
|| issueType=="Sub-Bug")
{
//Get fix versions of issue
Collection<Version> fixVersions = new ArrayList<Version>();
fixVersions = issue.getFixVersions();
def Parent = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Parent Fix Version");
def ParentFixVersion = issue.getCustomFieldValue(Parent) as Version;

//Get Epic Link Key
def epic = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Epic Link");
def epicKey = issue.getCustomFieldValue(epic);

if(fixVersions[0]!=ParentFixVersion)
{
UserMessageUtil.error("Failed. Fix version of issue should be like the Epic's fix version");
//ChangeHistoryManager changeHistoryManager = ComponentAccessor.getChangeHistoryManager();
//List<ChangeItemBean> changeList = changeHistoryManager.getChangeItemsForField(issue, "Fix Version")
//return changeList[0].toString.class;
issue.setFixVersions([ParentFixVersion])
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)
}
}

It didn't change the fix version...

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.
Jul 26, 2018

Could you remove the if condition? I think it does not pass your if conditions. Also you need to use logging to find what is going on in your script. 

https://www.adaptavist.com/doco/display/SFJ/Set+logging+to+help+debug+your+scripts

The if condition is passed, cause the error message that inside the condition is happened

The log:

2018-07-26 10:57:54,345 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2018-07-26 10:57:54,345 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: <inline script>
java.lang.ClassCastException: java.lang.String cannot be cast to com.atlassian.jira.project.version.Version
 at com.atlassian.jira.project.version.DefaultVersionManager.updateIssueValue(DefaultVersionManager.java:577)
 at com.atlassian.jira.project.version.DefaultVersionManager.updateIssueFixVersions(DefaultVersionManager.java:565)
 at com.atlassian.jira.issue.fields.FixVersionsSystemField.updateIssueValue(FixVersionsSystemField.java:98)
 at com.atlassian.jira.issue.fields.AbstractVersionsSystemField.updateValue(AbstractVersionsSystemField.java:372)
 at com.atlassian.jira.issue.managers.DefaultIssueManager.updateFieldValues(DefaultIssueManager.java:704)
 at com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue(DefaultIssueManager.java:669)
 at com.atlassian.jira.issue.managers.DefaultIssueManager.updateIssue(DefaultIssueManager.java:655)
 at com.atlassian.jira.issue.managers.RequestCachingIssueManager.updateIssue(RequestCachingIssueManager.java:214)
 at com.atlassian.jira.issue.IssueManager$updateIssue$1.call(Unknown Source)
 at Script3832.run(Script3832.groovy:47)

and:

2018-07-26 11:50:59,716 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2018-07-26 11:50:59,717 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: <inline script>
java.lang.NoClassDefFoundError: groovy/lang/GroovyObject
 at Script3906.run(Script3906.groovy:33)
 at com.onresolve.scriptrunner.runner.ScriptRunnerImpl.runScriptAndGetContext(ScriptRunnerImpl.groovy:156)
 at com.onresolve.scriptrunner.runner.ScriptRunner$runScriptAndGetContext$0.callCurrent(Unknown Source)
 at com.onresolve.scriptrunner.runner.ScriptRunnerImpl.runStringAsScript(ScriptRunnerImpl.groovy:144)
 at com.onresolve.scriptrunner.runner.ScriptRunner$runStringAsScript.call(Unknown Source)
 at com.onresolve.scriptrunner.canned.jira.workflow.listeners.CustomListener.doScript(CustomListener.groovy:118)
Caused by: java.lang.ClassNotFoundException: groovy.lang.GroovyObject
 ... 6 more

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events