Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Options class giving error in groovy script

Omprakash Thamsetty
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.
August 14, 2015

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

 

6 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Omprakash Thamsetty
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.
August 19, 2015

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.

Guilherme Nogueira
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.
August 19, 2015

so this is another error? not the first one?

Guilherme Nogueira
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.
August 19, 2015

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

Omprakash Thamsetty
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.
August 19, 2015

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?

1 vote
Omprakash Thamsetty
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.
August 18, 2015
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

 

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:
Whats wrong in my code? Where is duplicate class defined in the code.
JamieA
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.
August 18, 2015

How is the listener configured? Can you add a screenshot of the config?

Omprakash Thamsetty
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.
August 18, 2015

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

1 vote
Jon Mort [Adaptavist]
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.
August 14, 2015

I believe you need to import com.atlassian.jira.issue.customfields.option.Options instead of com.atlassian.jira.issue.search.searchers.renderer.Options

0 votes
Omprakash Thamsetty
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.
August 17, 2015
Here is the error I am getting when I put in script listener. It is working fine in script console. Can you please review my code and let me know if any thing wrong.
Problem loading class: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: D:\Atlassian\Application Data\JIRA\scripts\fssa\listener\DMA_Update_SubTaskFromParent.groovy: 19: Invalid duplicate class definition of class DMA_Update_SubTaskFromParent : The sources D:\Atlassian\Application Data\JIRA\scripts\fssa\listener\DMA_Update_SubTaskFromParent.groovy and file:/D:/Atlassian/Application%20Data/JIRA/scripts/fssa/listener/DMA_Update_SubTaskFromParent.groovy each contain a class with the name DMA_Update_SubTaskFromParent. @ line 19, column 1. ComponentManager componentManager = ComponentManager.getInstance() ^ 1 error
Code:

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()

    }

  

   }

 

 

JamieA
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.
August 18, 2015

Please use the {code} macro to format your code otherwise it's unreadable.

Omprakash Thamsetty
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.
August 18, 2015

Jamie, Can you please explain bit more about {code} Macro. I am new to writing groovy script.

JamieA
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.
August 18, 2015

Edit your question/answer and put your code in a {code} block.

0 votes
Omprakash Thamsetty
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.
August 14, 2015

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

Guilherme Nogueira
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.
August 14, 2015

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

Guilherme Nogueira
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.
August 14, 2015

no sorry, just finishing something here. please dismiss my comment.

Omprakash Thamsetty
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.
August 14, 2015

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 ?

Guilherme Nogueira
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.
August 14, 2015

Hi, I just changed my answer to a code that should work. Check that.

Guilherme Nogueira
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.
August 14, 2015

Sorry I'm late but I was busy hahaha

Guilherme Nogueira
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.
August 17, 2015

My answer worked?

Omprakash Thamsetty
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.
August 17, 2015

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)

Guilherme Nogueira
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.
August 17, 2015

I forgot one line after imports: def issue = componentManager.getIssueManager().getIssueObject()

0 votes
Guilherme Nogueira
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.
August 14, 2015

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);

 

 

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events