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
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:
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
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.
Can you provide errors and the whole script?
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.
Hover the mouse over the ComponentAccessor, which is underlined in red. You will see errors. Make a screenshot.
Also provide the whole script
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What is your Jira version? Try to execute this script in a a listnere and have a look in the atlassian-jira.log file.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can read about atlassian-jira.log here
https://confluence.atlassian.com/adminjiraserver073/logging-and-profiling-861253813.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The same error :( start with this line:
def issue = ComponentAccessor.getIssueManager().getIssueObjectByCurrentKey(event.getIssue().getKey());
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What error? No such property? not possible
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
}
}
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.
You can skip this error. It will work just fine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.