Hi,
I am writing the code for updating parentTask "select List" value to subtask. I found the way to do this by following this URL
https://answers.atlassian.com/questions/296363
but getting the error for options class as below
Error
Cannot cast object '[major,minor,low]' with class 'com.atlassian.jira.issue.customfields.option.OptionsImpl' to class 'com.atlassian.jira.issue.search.searchers.renderer.Options' due to: groovy.lang.GroovyRuntimeException: Could not find matching constructor for: com.atlassian.jira.issue.search.searchers.renderer.Options(com.atlassian.jira.issue.customfields.option.LazyLoadedOption, com.atlassian.jira.issue.customfields.option.LazyLoadedOption, com.atlassian.jira.issue.customfields.option.LazyLoadedOption, com.atlassian.jira.issue.customfields.option.LazyLoadedOption, com.atlassian.jira.issue.customfields.option.LazyLoadedOption, com.atlassian.jira.issue.customfields.option.LazyLoadedOption, com.atlassian.jira.issue.customfields.option.LazyLoadedOption, com.atlassian.jira.issue.customfields.option.LazyLoadedOption)
I included the following class for options
import com.atlassian.jira.issue.search.searchers.renderer.Options
Am I missing any thing ?
Thanks
Community moderators have prevented the ability to post new answers.
I am still having the problem with my code in script listener. Its working for me in script console but not in script listener. What was wrong in my code. I am not getting why it is showing "Invalid duplicate class definition of class ".
Any help much appreciate.
so this is another error? not the first one?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In this error try to change this field: Name of Groovy Class : foldername.listener.scriptname use something like: Name of Groovy Class : foldername.listener.CHANGETHIS
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, I did that changes. Its not giving error for first time. Its even not working the script as expected. Like not changing the select list value but its working when I put in script console. One more thing when I change the groovy script name and then update works only first time. If I want to change or edit the script then click on update in script listener then getting the error as " Problem loading class: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: D:\Atlassian\Application Data\JIRA\scripts\scriptname.groovy: 19: Invalid duplicate class definition of class scriptname : The sourcesD:\Atlassian\Application Data\JIRA\scripts\scriptname.groovy and file:/D:\Atlassian\Application Data\JIRA\scripts\scriptname.groovyeach contain a class with the name scriptname. @ line 19, column 1. ComponentManager componentManager = ComponentManager.getInstance() ^ 1 error Code: Do you have any idea on it?
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.ComponentManager import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.issue.Issue import com.atlassian.jira.config.SubTaskManager import com.atlassian.jira.issue.customfields.manager.OptionsManager import com.atlassian.jira.issue.customfields.option.Options import com.atlassian.jira.issue.util.DefaultIssueChangeHolder import com.atlassian.jira.issue.customfields.option.* import com.atlassian.jira.issue.ModifiedValue ComponentManager componentManager = ComponentManager.getInstance() CustomFieldManager customFieldManager = componentManager.getCustomFieldManager() //def optionsManager = ComponentManager.getComponentInstanceOfType(OptionsManager.class) OptionsManager optManager = ComponentAccessor.getOptionsManager(); def P_Priority = customFieldManager.getCustomFieldObjectByName("Priority") def P_PriorityVal = issue.getCustomFieldValue(P_Frequency).getValue() def fieldConfig = P_Frequency.getRelevantConfig(issue) def option = optManager.getOptions(fieldConfig).find {it.toString() == P_FreqVal} SubTaskManager subTaskManager = ComponentManager.getInstance().getSubTaskManager(); Collection subTasks = issue.getSubTaskObjects() if (subTaskManager.subTasksEnabled && !subTasks.empty) { subTasks.each { CustomField S_Priority = customFieldManager.getCustomFieldObjectByName('Priority') S_PriorityVal = it.getCustomFieldValue(S_Priority) if(S_PriorityVal != P_PriorityVal){ DefaultIssueChangeHolder issueChangeHolder = new DefaultIssueChangeHolder(); S_Priority.updateValue(null,it,new ModifiedValue(S_Priority,option),issueChangeHolder) S_Priority.store(); } it.store() } }
This runs in script console but not running in script listener. Error Message is
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How is the listener configured? Can you add a screenshot of the config?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Went to Atlassian --> Add On --> Script Listeners --> Custom Listener Note : Update SubTask From Parent (Description and Frequency) Project key: Choosen the Project Name Events : Issue Updated Name of Groovy Class : foldername.listener.scriptname
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I believe you need to import com.atlassian.jira.issue.customfields.option.Options
instead of com.atlassian.jira.issue.search.searchers.renderer.Options
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.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.config.SubTaskManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.Options
//import com.atlassian.jira.issue.search.searchers.renderer.Options
//import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
//import com.atlassian.jira.issue.customfields.option.OptionsImpl
//import com.atlassian.jira.issue.util.IssueChangeHolder
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
//import com.atlassian.jira.issue.search.SearchProvider;
import com.atlassian.jira.issue.customfields.option.*
import com.atlassian.jira.issue.ModifiedValue
////////////////////////////////////////////////////////////////////////////////////////
//Used for testing on specific issue
ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
////////////////////////////////////////////////////////////////////////////////////////
//def optionsManager = ComponentManager.getComponentInstanceOfType(OptionsManager.class)
OptionsManager optManager = ComponentAccessor.getOptionsManager();
def P_Priority = customFieldManager.getCustomFieldObjectByName("Priority")
def P_PriorityVal = issue.getCustomFieldValue(P_Frequency).getValue()
def fieldConfig = P_Frequency.getRelevantConfig(issue)
//Options options = optManager.getOptions(fieldConfig)
def option = optManager.getOptions(fieldConfig).find {it.toString() == P_FreqVal}
//Option newOption = options.getOptionByValue(P_FreqVal);
SubTaskManager subTaskManager = ComponentManager.getInstance().getSubTaskManager();
Collection subTasks = issue.getSubTaskObjects()
if (subTaskManager.subTasksEnabled && !subTasks.empty) {
subTasks.each {
//Set the Frequency if changed.
CustomField S_Priority = customFieldManager.getCustomFieldObjectByName('Priority')
S_PriorityVal = it.getCustomFieldValue(S_Priority)
if(S_PriorityVal != P_PriorityVal){
DefaultIssueChangeHolder issueChangeHolder = new DefaultIssueChangeHolder();
S_Priority.updateValue(null,it,new ModifiedValue(S_Priority,option),issueChangeHolder)
S_Priority.store();
}
//Save the changes made above.
it.store()
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please use the {code} macro to format your code otherwise it's unreadable.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Jamie, Can you please explain bit more about {code} Macro. I am new to writing groovy script.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Edit your question/answer and put your code in a {code} block.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jonathan and Guilherme, Thanks for the reply. I kept the import both but still getting the same error. Here are the imports that I have in my script
import com.atlassian.jira.ComponentManager import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.config.SubTaskManager
import com.atlassian.jira.issue.customfields.manager.OptionsManager import com.atlassian.jira.issue.customfields.option.Options import com.atlassian.jira.issue.search.searchers.renderer.Options import com.atlassian.jira.issue.customfields.option.LazyLoadedOption import com.atlassian.jira.issue.customfields.option.OptionsImpl import com.atlassian.jira.issue.util.IssueChangeHolder import com.atlassian.jira.issue.util.DefaultIssueChangeHolder import com.atlassian.jira.issue.search.SearchProvider; import com.atlassian.jira.issue.customfields.option.* import com.atlassian.jira.issue.ModifiedValue
Piece of code is
ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
def issue = componentManager.getIssueManager().getIssueObject()
OptionsManager optManager = ComponentAccessor.getOptionsManager();
def Parentcfname = customFieldManager.getCustomFieldObjectByName("cfName")
def ParentcfVal = issue.getCustomFieldValue(Parentcfname).getValue()
def fieldConfig = P_Frequency.getRelevantConfig(issue)
Options options = optManager.getOptions(fieldConfig)
//def option = optionsManager.getOptions(fieldConfig).find {it.toString() == ParentcfVal}
Option newOption = options.getOptionById(P_FreqVal.toString());
SubTaskManager subTaskManager = ComponentManager.getInstance().getSubTaskManager();
Collection subTasks = issue.getSubTaskObjects()
CustomField SubTaskcfName = customFieldManager.getCustomFieldObjectByName('cfName')
subTaskcfVal = it.getCustomFieldValue(subTaskcfName)
DefaultIssueChangeHolder issueChangeHolder = new DefaultIssueChangeHolder(); SubtaskcfName.updateValue(null,it,new ModifiedValue(SubTaskcfVal,newOption),issueChangeHolder) SubTaskcfName.store();
Than got error as shown in original post.
any help much appreciate on it
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
sec... import com.atlassian.jira.ComponentManager import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.issue.Issue import com.atlassian.jira.config.SubTaskManager import com.atlassian.jira.issue.customfields.manager.OptionsManager import com.atlassian.jira.issue.customfields.option.Options import com.atlassian.jira.issue.search.searchers.renderer.Options import com.atlassian.jira.issue.customfields.option.LazyLoadedOption import com.atlassian.jira.issue.customfields.option.OptionsImpl import com.atlassian.jira.issue.util.IssueChangeHolder import com.atlassian.jira.issue.util.DefaultIssueChangeHolder import com.atlassian.jira.issue.search.SearchProvider; import com.atlassian.jira.issue.customfields.option.* import com.atlassian.jira.issue.ModifiedValue
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
no sorry, just finishing something here. please dismiss my comment.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I commented the import com.atlassian.jira.issue.search.searchers.renderer.Options then error gone but finding the way to get option selected in select List field as I don't know the IDs in below code Option newOption = options.getOptionByValue(ParentcfValue); Is there any other way to find the selected option ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, I just changed my answer to a code that should work. Check that.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry I'm late but I was busy hahaha
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My answer worked?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am getting below error when I run the script but I had made it work with another code . Issue is now keeping the code in script listener and getting error as duplicate object. Updating in comment for error. Error No such property: issue for class: Script269 groovy.lang.MissingPropertyException: No such property: issue for class: Script269 at Script269.run(Script269.groovy:12)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I forgot one line after imports: def issue = componentManager.getIssueManager().getIssueObject()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Check now, maybe you need to do a few changes but I hope it help.
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.issue.customfields.manager.OptionsManager import com.atlassian.jira.issue.util.IssueChangeHolder import com.atlassian.jira.issue.ModifiedValue import com.atlassian.jira.issue.util.DefaultIssueChangeHolder import com.atlassian.jira.issue.Issue import org.apache.log4j.Category Parentcfname = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("cfName") IssueChangeHolder changeHolder = new DefaultIssueChangeHolder(); def String ParentcfVal = issue.getCustomFieldValue(Parentcfname) ?: 0 def componentManager = ComponentManager.instance def fieldConfig = Parentcfname.getRelevantConfig(issue) def optionsManager = componentManager.getComponentInstanceOfType(OptionsManager.class) def newOption = optionsManager.getOptions(DPWeek_fieldConfig).getOptionForValue(ParentcfVal,null) Parentcfname.updateValue(null, it, new ModifiedValue(it.getCustomFieldValue(Parentcfname), newOption), changeHolder);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.